Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Editing just one column in a file

by vinian (Beadle)
on Nov 29, 2011 at 09:00 UTC ( [id://940555]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Editing just one column in a file
in thread Editing just one column in a file

thanks, but i got something more strange
vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[0..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[1..3]' another vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[2..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just vinian@cc:~$ echo "Just another perl monker" | perl -w -lane 'print $F +[3..3]' Argument "" isn't numeric in array element at -e line 1, <> line 1. Just

when $F[1..3] there is no warnings and the output is $F[1]

Replies are listed 'Best First'.
Re^5: Editing just one column in a file
by choroba (Cardinal) on Nov 29, 2011 at 10:13 UTC
    In scalar context, the .. operator with numeric constants is interpreted as line range. As you are reading lines with -n and you are on the first line, 1..3 evaluates to 1. All other ranges evaluate to undef (stringified to ''), because the first line is out of the range, and that's why you get the warning.
Re^5: Editing just one column in a file
by Tux (Canon) on Dec 01, 2011 at 07:35 UTC

    You should've used @ again:

    $ echo "Just another perl monker" | perl -w -lane 'print @F[1..3]' anotherperlmonker $ echo "Just another perl monker" | perl -wanE'say@F[1..3]' anotherperlmonker $ echo "Just another perl monker" | perl -w -lane 'print @F[3..3]' monker $ echo "Just another perl monker" | perl -wanE'say@F[3..3]' monker $

    Enjoy, Have FUN! H.Merijn

      3ks, Tux, I know it's wrong to use $[ $index_begin .. $index_end ], but i want to why range operator produce strange result in different content( scalar or list).
      and also 3ks choroba, i think I got it after seeing what you posted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://940555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found