Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Pre-process csv files before using

by sk (Curate)
on Aug 06, 2005 at 19:20 UTC ( #481539=note: print w/replies, xml ) Need Help??


in reply to Re^4: Pre-process csv files before using
in thread Pre-process csv files before using

The code I gave you above should do what you are looking for.

perl -e'@cols =qw (field1 fieldband field3 fieldMSTCP okfield5); for ( +@cols) { push(@req,$_) unless /band.*|MSTCP.*/;} print join (",",@req +),$/;' __END__ field1,field3,okfield5

Here i am excluding names with band and MSTCP field names. Since I don't have any field names I am just hard coding it here

. -SK

Replies are listed 'Best First'.
Re^6: Pre-process csv files before using
by DrAxeman (Scribe) on Aug 06, 2005 at 20:03 UTC
    I'm getting an odd error with this
    shift @origcols; foreach ( @origcols ) { $_ =~ s/\.//; push ( @cols , $_ ) unless /Bandwidth.*|MSTCPLoop.*/ ; }

    It says:
    Use of uninitialized value in substitution (s///) at ./runsql3.sql lin +e 20. Use of uninitialized value in pattern match (m//) at ./runsql3.sql lin +e 21.
    Line 20 is my "s/\.//" line
      I would check if there are proper values in your @origcols array.

      Do something like this before you get into the loop to modify it

      map { print $_,$/ } @origcols;
      If you see proper output then need to look at other places. Example of your header data will be helpful!

      Actually davidrw's grep solution is much cleaner!

        This is a small sample of the header data

        PDHCSV40EasternDaylightTime240,ERWWCOMMUNITIES.MemoryPagesPERsec,ERWWC +OMMUNITIESNetworkInterfaceEthernetAdapterModuleBytesTotalPERsec,ERWWC +OMMUNITIESNetworkInterfaceEthernetAdapterCurrentBandwidth

        In the original data, some of the headers have periods in them. This causes SQL error, so I've been stripping them in a preprocessing program. I'm trying to stream line this, and get rid of the preprocessor.

        To test this I've been adding a period in one of the fields. Thats when I get the error. I have inserted a period in the second header value to simulate what I am trying to strip.

        20050807 Janitored by Corion: Made page-widening code wrap (only multiline code wraps)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-11-29 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?