470,581 Members | 2,357 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,581 developers. It's quick & easy.

awk's NF in Perl

Hi all,

I want to have the awk NF variable in Perl. Yes I know there are many
hints for that. But I only found the folloing:

#!/usr/bin/perl

$ln="1;2;3;4;;;;;;10";
$nf = @records = split(/;/, $ln);
print "NF:$nf\n";
$"=";";
print "@records\n";

output:
NF:10
1;2;3;4;;;;;;10

so it looks good, now I change the script a little bit, look here:

# change this line in script:
$ln="1;2;3;4;;;;;;";

output:
NF:4
1;2;3;4

So now you can see the trick with spilt did not work any time. Are
there any other suggestions out there?

ciao
Thorsten
Jul 19 '05 #1
1 4517
In article <be*************************@posting.google.com> , Thorsten
Gottschalk <iq****@web.de> wrote:
Hi all,

I want to have the awk NF variable in Perl. Yes I know there are many
hints for that. But I only found the folloing:

#!/usr/bin/perl
use strcit:
use warnings;

$ln="1;2;3;4;;;;;;10";
my $ln = "1;2;3;4;;;;;;;";
$nf = @records = split(/;/, $ln);
my $nf = my @records = split(/;/, $ln, -1 );
print "NF:$nf\n";
$"=";";
print "@records\n";

output:
NF:10
1;2;3;4;;;;;;10

so it looks good, now I change the script a little bit, look here:

# change this line in script:
$ln="1;2;3;4;;;;;;";

output:
NF:4
1;2;3;4
NF:10
1;2;3;4;;;;;;;

So now you can see the trick with spilt did not work any time. Are
there any other suggestions out there?

ciao
Thorsten


Check the documentation on split:

perldoc -f split

FYI: this newgroup is defunct. Try comp.lang.perl.misc in the future.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dan Jacobson | last post: by
20 posts views Thread by Matthew Thorley | last post: by
13 posts views Thread by NNTP | last post: by
2 posts views Thread by gorda | last post: by
3 posts views Thread by Anthony Smith | last post: by
15 posts views Thread by jyo123 | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.