Objectmix
Tags Register Mark Forums Read

awk's NF in Perl : Perl

This is a discussion on awk's NF in Perl within the Perl forums in Programming Languages category; 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...


Object Mix > Programming Languages > Perl > awk's NF in Perl

Reply

 

LinkBack Thread Tools
  #1  
Old 03-05-2004, 07:05 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-05-2004, 03:04 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: awk's NF in Perl

In article <beb38f7.0403050405.6c3988df@posting.google.com> , Thorsten
Gottschalk <iqrity@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.
Reply With Quote
Reply

Thread Tools


Similar Threads

Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? usenet Perl 0 11-22-2007 03:03 AM
How to gram awk's regexp submatches? usenet awk 5 11-20-2007 06:58 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? usenet Perl 0 09-06-2007 02:03 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? usenet Perl 0 06-27-2007 08:03 AM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? usenet Perl 0 04-18-2007 02:03 AM


All times are GMT -5. The time now is 08:42 AM.