chen li wrote:
>
> --- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
>>
>>$ perl -le'
>>my $string = q[ a b c d ];
>>print join "\t", map "<$_>", split q[\s+],
>>qq[$string], q[4];
>>print join "\t", map "<$_>", split /\s+/,
>>$string, 4;
>>'
>><> <a> <b> <c d >
>><> <a> <b> <c d >
>>
>>$ perl -le'
>>my $w = 3;
>>my $x = 7;
>>my $y = 2;
>>my $z = 6;
>>
>>print join "\t", map "<$_>", split $w * $x - $y *
>>$z, q[one] . ( $w + $z ) .
>>q[two] . ( $x + $y ) . q[three];
>>'
>><one> <two> <three>
>
> split /PATTERN/,EXPR,LIMIT
> split /PATTERN/,EXPR
> split /PATTERN/
> split
>
> 1. I check the perldoc -f split but I am not quite
> sure what EXPR really means.
It basically means any valid perl code.
> Does it refer to a string,
Yes.
> or a scalar variable contaning a string,
Yes.
> or an array?
No.
> From what I learn from camel book I don't find
> an example that shows "split" can work on an array.
It can't. split forces scalar context on its arguments so an array would be
seen by split as a number (the number of elements in the array.)
> But it works fine for my array transition. Am I
> missing something?
One example uses map to split each individual array element and the other
example converts the array to a string (scalar) first.
> 2. In this line $ perl -le what does -le mean?
perldoc perlrun
[snip]
-e commandline
may be used to enter one line of program. If -e is given, Perl
will not look for a filename in the argument list. Multiple -e
commands may be given to build up a multi-line script. Make sure
to use semicolons where you would in a normal program.
[snip]
-l[octnum]
enables automatic line-ending processing. It has two separate
effects. First, it automatically chomps $/ (the input record
separator) when used with -n or -p. Second, it assigns "$\" (the
output record separator) to have the value of octnum so that any
print statements will have that separator added back on. If
octnum is omitted, sets "$\" to the current value of $/. For
instance, to trim lines to 80 columns:
perl -lpe 'substr($_, 80) = ""'
Note that the assignment "$\ = $/" is done when the switch is
processed, so the input record separator can be different than the
output record separator if the -l switch is followed by a -0
switch:
gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
This sets "$\" to newline and then sets $/ to the null character.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>