Why is it that this
perl -lane '$,="\t"; print @F[0..4] ."\t\t\t" . @F[25..30]' file.txt
Does not do what I intended ( for the ranges to be printed by tabs, followed by three blank columns followed by another range). Thankyou for your help!
| [reply] [Watch: Dir/Any] [d/l] |
Because $, is the character used when you give a list of values to the print statement, but you've used '.'s.
Ie. You're giving the print statement a single (concatenated) value, therefore the item separator is never used.
This might achieve your goal:
perl -lane '$,="\t"; print @F[0..4], "\t\t\t", @F[25..30]' file.txt
but "three blank columns" is a very nebulous concept.
Update: FTR, I might code that as: print join "\t", @F[0..4], ('')x3, @F[25..30];
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
| [reply] [Watch: Dir/Any] [d/l] [select] |
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] | [reply] [Watch: Dir/Any] [d/l] [select] |
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.
| [reply] [Watch: Dir/Any] [d/l] [select] |
$ 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
| [reply] [Watch: Dir/Any] [d/l] [select] |
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.
| [reply] [Watch: Dir/Any] [d/l] |