Using semicolon delimited autosplit "perl -aF\;"

C

C Marshall

I haven't had any luck managing to autosplit on the semi colon
character under AIX when putting my commandline options into a script.

i.e. whilst

echo "1;2;3"| perl -anl -F\; -e 'print "$F[1]"'
2

works correctly I cannot reproduce the effects in a script

eg
echo "1;2;3"| test.pl
Use of uninitialized value in string at test.pl line 4, <> line 1 (#1)

(W uninitialized) An undefined value was used as if it were
already defined. It was
interpreted as a "" or a 0, but maybe it was a mistake. To
suppress this
warning assign a defined value to your variables.

where test.pl is:
#!/usr/bin/perl -awnl -F\;
use diagnostics;

print "$F[1]";


I've tried a variety of formats for the -F line e.g
"\;"
""\;""
"'\;'"
";"
\073
\x3A
/\073/
/\;/

etc. to no avail.

Any idea where I'm going wrong ?

perl, v5.6.0 built for aix

Thanks
Chris
 
C

C Marshall

I haven't had any luck managing to autosplit on the semi colon
character under AIX when putting my commandline options into a script.


I've found that I can get away with a simple -F\; as long as this is
not the last flag I use - and that the flag after this will then be
ignored.

Therefore
#!/usr/bin/perl -awlnF\; --


seems to work perfectly - but I can't say I understand why.
 
J

John W. Krahn

C said:
I haven't had any luck managing to autosplit on the semi colon
character under AIX when putting my commandline options into a script.

i.e. whilst

echo "1;2;3"| perl -anl -F\; -e 'print "$F[1]"'
2

works correctly I cannot reproduce the effects in a script

eg
echo "1;2;3"| test.pl
Use of uninitialized value in string at test.pl line 4, <> line 1 (#1)

(W uninitialized) An undefined value was used as if it were
already defined. It was
interpreted as a "" or a 0, but maybe it was a mistake. To
suppress this
warning assign a defined value to your variables.

where test.pl is:
#!/usr/bin/perl -awnl -F\;
use diagnostics;

print "$F[1]";

[snip]

Any idea where I'm going wrong ?

You could always do the split explicitly.

#!/usr/bin/perl -wnl
use diagnostics;
@F = split /;/;
print "$F[1]";



John
 
B

Bob Walton

C said:
I haven't had any luck managing to autosplit on the semi colon
character under AIX when putting my commandline options into a script.

i.e. whilst

echo "1;2;3"| perl -anl -F\; -e 'print "$F[1]"'
2

works correctly I cannot reproduce the effects in a script

eg
echo "1;2;3"| test.pl
Use of uninitialized value in string at test.pl line 4, <> line 1 (#1)

(W uninitialized) An undefined value was used as if it were
already defined. It was
interpreted as a "" or a 0, but maybe it was a mistake. To
suppress this
warning assign a defined value to your variables.

where test.pl is:
#!/usr/bin/perl -awnl -F\;
use diagnostics;

print "$F[1]";


I've tried a variety of formats for the -F line e.g
"\;"
""\;""
"'\;'"
";"
\073
\x3A
/\073/
/\;/

etc. to no avail.

Any idea where I'm going wrong ?

perl, v5.6.0 built for aix ....


Chris

Hmmmmm...seems to work fine under Windoze, with or

without the \ in the -F; in the script shebang line.

Maybe it's some idiosyncrasy in AIX with

shebang-line options? Or with whatever shell you

are using? You might want to turn off

warnings, though, since if an input line does not
split into at least two pieces, you will get the
warning you got.

Since you are writing a script rather than doing
a 1-liner, why not just code out the loops and
the split? Then you don't have to worry about
the vagaries of shebang line interpretation.

It is probably more of a Unix / shell issue than
a Perl issue.
 
C

C Marshall

CM>> I haven't had any luck managing to autosplit on the semi colon
CM>> character under AIX when putting my commandline options into a
script.


BW> You might want to turn off warnings, though, since if an input
line does not
BW> split into at least two pieces, you will get the warning you got.

Well of course I will once the script is used - though I've learnt
better than to post my sample code here without warnings turned on :)
Here be Tad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top