gio001 has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone,

I have a question on a change I need to apply to the following code:

perl -sple"BEGIN{open BIG};($undef,$l)=split;read(BIG,$_,$l)" -- -BIG= +bigfile.dat index.dat >outfile.dat
As you can see I have 2 files one is data the other is an index file with offset and length for each of the record in the data file. I would like to modify this command in such a way that I can also pass let's say three string vars (could they also be regexp's?), and at the completion of the modified command it will return 3 counts (one per passed var) each count will tell me how many of the records contained var1 or var2 or var3.

I hope one of you wise perl monks can help me out.

Thanks!

Replies are listed 'Best First'.
Re: Load file from offset file
by NetWallah (Canon) on Mar 29, 2011 at 06:38 UTC
    Your code, initial statement and final question all seem unrelated.

    Here is my interpretation of what you seem to be requesting:

    perl -ne 'm/($find)/ and $x{$1}++}{print qq|FIND=$find;\n|;print qq|$ +_\t$x{$_}\n| for sort keys %x' -s -- -find=var1\|var2\|var3 YourFileN +ame.txt
    You seem to be on Windows. Use Double-quotes instead of single. You may also need to escape the pipe characters differently.

    The code above will count the number of times 'var1','var2' and 'var3' occurs in YourFileName.txt.

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

      Thanks for your suggestion.

      I will try your code shortly.

      To better clarify my question: I am on unix, and the perl statemt will appear inside a ksh script that I am writing to analyze the contents of large files.

      The statememt I supplied in the question is responsible to build the file by using the index file and assembling all of the data from the incoming file into the output file, and have these pieces of info returned to me also.

      This seems to work properly.

      What I am asking was the possibility to tag on some additional code that would tally the various counters I am interested in during the building of the output file.

      I hope this makes my question a bit clearer.

      Thanks.
Re: Load file from offset file (move along, nothing to see here)
by Anonymous Monk on Mar 29, 2011 at 06:52 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Load file from offset file
by Anonymous Monk on Mar 29, 2011 at 06:42 UTC
    would like to modify this command in such a way that I can also pass let's say three string vars (could they also be regexp's?), and at the completion of the modified command it will return 3 counts (one per passed var) each count will tell me how many of the records contained var1 or var2 or var3

    Would you really write a KSH script this complicated as a one-liner? No.

    Make your oneliner start with perl -MO=Deparse, and use the output as the basis of a perl program