Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: raw data formatting

by teamassociated (Novice)
on Nov 16, 2012 at 01:45 UTC ( #1004098=note: print w/ replies, xml ) Need Help??


in reply to Re: raw data formatting
in thread raw data formatting

Looks awesome, but I get errors: it does not like the /r, but does fine with /e except the output is all 11111.

# perl -c foobar Bareword found where operator expected at foobar line 12, near "s/\s+/ +$letter++ . ' '/er" syntax error at foobar line 12, near "s/\s+/$letter++ . ' '/er " foobar had compilation errors. root@facs04ap [/var/adm/scripts] # perl -v This is perl, v5.8.8 built for aix-thread-multi

code from u

use strict; use warnings; use List::MoreUtils qw/natatime/; my $it = natatime 5, <DATA>; while ( my @lines = $it->() ) { my $letter = 'A'; my $acctNum = do { $lines[0] =~ /\s+(\d+)\s+(\d+)/; $1 . $2 }; push @lines, " acctnum=$acctNum"; print for map { s/\s+/$letter++ . ' '/er } @lines; print "\n"; } __DATA__ 50###### 8 Z Axxx ,xxxxxxx 19793.43 02/02/2012 06/08 +/2012 32989.05 037###### S JOYCE xxxxxxS .00 06/06/xxxx + 0 0 7 1471 xxxx xxxx x #101 .00 02/08/2012 + 06/15/2012 NOV 0 U MILWAUKEE, WI xxxxx 32989.05 02/08/2012 + 3 3##### MILWAUKEE WI .00 5321 +4 12 50##### 8 Z Axxx ,Nxxxxx 75.00 05/27/2012 06/ +05/2012 1845.00 03######3 E Nxxxx Axxxx .00 09/xx/xxxx 06/ +05/2012 MYT##### 7####### S 156xxx xxxxx BLVD .00 06/06/2012 06/ +14/2012 MYT######## NOV 0 C TAYLOR,MI 48180 1845.00 05/27/2012 + 3 3 37###### S TAYLOR MI .00 48 +180 3 12 50##### 9 Z ALxxxx Rxxxx ,SUSxxx 75.00 05/05/2012 05/15 +/2012 2045.00 0000000000 E SUSE Axxxxx Rxxxx .00 03/xx/xxxx 05/1 +5/2012 AJT9####### 31####### 44xxx xxx AVE .00 05/16/2012 0 +6/15/2012 AJT92###### NOV 0 C LINCOLN PARK,MI xxxxx 2045.00 05/05/2012 + 1 3 0 S LINCOLN PARK MI .00 4 +8146 1 12


Comment on Re^2: raw data formatting
Select or Download Code
Re^3: raw data formatting
by Kenosis (Priest) on Nov 16, 2012 at 01:52 UTC

    Your version of Perl doesn't support the non-destructive substitution modifier (/r). Use the following:

    print for map { s/\s+/$letter++ . ' '/e; $_ } @lines;

    Will make that change in the original posting.

      Thank you that worked! This code technique is new 2 me, but thanks! I need to skip certain lines ...working in original code, but tried using it here. how do i skip indexes as opposed to lines?
      while ( my @lines = $it->() ) { next if ($. == 1..88); my $letter = 'A'; my $acctNum = do { $lines[0] =~ /\s+(\d+)\s+(\d+)/; $1 . $2 }; push @lines, " acctnum=$acctNum"; print for map { s/\s+/$letter++ . ' '/e; $_ } @lines; print "\n"; }

        What do the indexes look like, i.e., how do they appear in your file?

        Noticed that line "F" doesn't wrap if it's the very last DATA line, since it doesn't have a newline at it's end. Thus, make the following two changes and I'll do the same in the original posting:

        while ( chomp( my @lines = $it->() ) ) {

        and

        print for map { s/\s+/$letter++ . ' '/e; "$_\n" } @lines;

        Remove the print "\n"; line.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-08-23 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls