Re: awk's NF in Perl

From: Jim Gibson (jgibson_at_mail.arc.nasa.gov)
Date: 03/05/04


Date: Fri, 05 Mar 2004 12:04:01 -0800

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.



Relevant Pages

  • Re: splitting a very large file based on characters in a record (performance)
    ... X (each of 125 characters), and further I have to split the 125 ... While I use awk for most of my text manipulation work, ... personal experience perl will be much faster than awk. ... that I had an awk script and a perl script that read sendmail files to ...
    (comp.unix.shell)
  • Re: unix command to delete parts of a file
    ... I'd like to ask if there's a unix command that could delete ... "true" and the default action for any condition that holds true in awk ... A Perl version of his would be trivial as well. ... handling --- like if the perl script is killed abruptly in mid-file) ...
    (comp.unix.admin)
  • Re: Strange Bash behavior
    ... I can only use Bash in my environment, could you please give me some ... if I have perl in front of the pipe I'd write the whole awk thing in perl ... Ah, indeed, my above script is a simple demo to make the problem ...
    (comp.unix.shell)
  • little script information
    ... Can someone point to me being a newbie how can i do a little script in ... awk or bash ...
    (comp.unix.shell)
  • awks NF in Perl
    ... I want to have the awk NF variable in Perl. ... hints for that. ... But I only found the folloing: ... so it looks good, now I change the script a little bit, look here: ...
    (comp.lang.perl)