[sf-perl] Anyone know why won't this work?

Randy J. Ray rjray at blackperl.com
Wed Jul 24 10:21:05 PDT 2013


On 07/24/2013 10:12 AM, Richard Reina wrote:
> Sorry I'm still confused.  I get the same thing when I put string in
> double quotes.
>
> #!/usr/bin/perl -w
>
> my $string = "The good\n\nThe bad\n\nThe Ugly";
>
> my @str = split /\n\n/, $string;
>
> print "Second thru last element: " . $str[1..$#str] . "\n";
>
> OUTPUT:
>
> perl test_split.pl
> Use of uninitialized value within @str in range (or flip) at
> test_split.pl line 7.
> Argument "" isn't numeric in array element at test_split.pl line 7.
> Second thru last element: The good

Oops, my bad. I didn't notice that you aren't really getting an array 
slice on the last line. That needs to be:

print "Second thru last element: " . @str[1..$#str] . "\n";

Note the "@" before str.

Randy
-- 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray      Sunnyvale, CA      http://www.rjray.org 
rjray at blackperl.com

Silicon Valley Scale Modelers: http://www.svsm.org


More information about the SanFrancisco-pm mailing list