Re: Update: Where to begin??!!??
On Fri, Jun 15, 2001 at 01:45:00PM -0700, Peter Cornelius ([EMAIL PROTECTED]) wrote: > > > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > You really want an 'or' here ---^^ not '||'. The operator precedence > can bite you. Only if you miss out the parenthesis around the parameters to 'open'. In this case || works just fine. Dave... -- .sig missing...
RE: Update: Where to begin??!!??
Gorp meant /\|/ as per Dave Cross's reply. > I would guess you really want #!/usr/bin/perl, spaces are > meaningful. And a > -w at the end can tell you a lot. > > #! usr/bin/perl > > use strict; > > > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > You really want an 'or' here ---^^ not '||'. The > operator precedence > can bite you. > > > open (FILE_OUT, ">pslbingocard.txt"); > > > > $/ = "\n"; > You shouldn't need to do this, $/ defaults to '\n' > > > > > while () { > > my ($date, $time, $name, $street, $city, $state, $zip, > > $country, $email, > > $phone, $submit, @subscriptions) = split (/|/, $/); > This splits the input record separator on the '|' character, > probably not > what you want. I think you really want just 'split /|/;' Gorp meant /\|/ as per Dave Crosses reply. > This will operate > on $_ which is the line you just read in from FILE_IN. > > > foreach my $subscription (@subscriptions) { # loop through the > > subscriptions array > > next unless $subscription += 0; # > I might be missing something, but why would this ever > succeed? Can't you > always add 0 to something? Are you trying to test for > strings? I don't > think this will do it. How about > > next unless $subscription =~ /\d+/; # next unless the > subscription contains > one or more digits > > > next unless $subscription =~ /\s/; > So... Only continue the loop if the subscription contains a > space? I'm not > sure why you need this. > > > $subscription =~s/^\s+//; > > $subscription =~s/\s+$//; > > $new_data .= > > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$ > > phone|$subscri > > ption|\n"; # create a new line for each bingo number. > > } > > print FILE_OUT $new_data; > > } > > > > > > Crystal > > I hope this is helpful, >
Re: Update: Where to begin??!!??
On Fri, Jun 15, 2001 at 04:43:26PM -0400, Michael Wolfrom ([EMAIL PROTECTED]) wrote: > > Dave Cross wrote: > > > > > > #! usr/bin/perl > > > use strict; > > > > > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > > > > You don't check the result of opening the output file. > > I think, in general, that it is good programming practice that you check > the opening of the output file. > What if your input file inludes a bad path? Er... exactly. That's what I was saying. Crystal checked the result of opening the input file, but not the output file. I was pointing that out, not saying it was a good idea :) Dave... -- Drugs are just bad m'kay
Re: Update: Where to begin??!!??
Well, it may not be necessary in that context, but I always escape them as they've sometimes caused headaches for me in the past. Greg --- Dave Cross <[EMAIL PROTECTED]> wrote: > On Fri, Jun 15, 2001 at 01:33:30PM -0700, Greg Meckes ([EMAIL PROTECTED]) wrote: > > First : > > Your assigning a newline to the "$/" scalar: $/ = "\n"; > > Why? Get rid of it. > > > > Second: > > The split: split (/|/, $/); > > Should be : split (/\|/, $_); > > > > Third: > > You should escape the pipes in the print statement: > > "$date|$time|$name|$street|etc"; > > Should be: |$date\|$time\|$name\|$street\|etc"; > > Greg, > > Your first two pieces of advice were spot on, but I can't see any reason why > you'd want to escape pipes in a print statement. > > Am I missing something obvious? > > Dave... > > -- > > Don't dream it... be it > __ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
RE: Update: Where to begin??!!??
I would guess you really want #!/usr/bin/perl, spaces are meaningful. And a -w at the end can tell you a lot. > #! usr/bin/perl > use strict; > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; You really want an 'or' here ---^^ not '||'. The operator precedence can bite you. > open (FILE_OUT, ">pslbingocard.txt"); > > $/ = "\n"; You shouldn't need to do this, $/ defaults to '\n' > > while () { > my ($date, $time, $name, $street, $city, $state, $zip, > $country, $email, > $phone, $submit, @subscriptions) = split (/|/, $/); This splits the input record separator on the '|' character, probably not what you want. I think you really want just 'split /|/;' This will operate on $_ which is the line you just read in from FILE_IN. > foreach my $subscription (@subscriptions) { # loop through the > subscriptions array > next unless $subscription += 0; # I might be missing something, but why would this ever succeed? Can't you always add 0 to something? Are you trying to test for strings? I don't think this will do it. How about next unless $subscription =~ /\d+/; # next unless the subscription contains one or more digits > next unless $subscription =~ /\s/; So... Only continue the loop if the subscription contains a space? I'm not sure why you need this. > $subscription =~s/^\s+//; > $subscription =~s/\s+$//; > $new_data .= > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$ > phone|$subscri > ption|\n"; # create a new line for each bingo number. > } > print FILE_OUT $new_data; > } > > > Crystal I hope this is helpful,
Re: Update: Where to begin??!!??
On Fri, Jun 15, 2001 at 01:33:30PM -0700, Greg Meckes ([EMAIL PROTECTED]) wrote: > First : > Your assigning a newline to the "$/" scalar: $/ = "\n"; > Why? Get rid of it. > > Second: > The split: split (/|/, $/); > Should be : split (/\|/, $_); > > Third: > You should escape the pipes in the print statement: > "$date|$time|$name|$street|etc"; > Should be: |$date\|$time\|$name\|$street\|etc"; Greg, Your first two pieces of advice were spot on, but I can't see any reason why you'd want to escape pipes in a print statement. Am I missing something obvious? Dave... -- Don't dream it... be it
Re: Update: Where to begin??!!??
On Fri, Jun 15, 2001 at 01:37:51PM -0700, Crystal Gruetzmacher ([EMAIL PROTECTED]) wrote: > what is $_ for? It's the "default" variable an is used for a great many things in Perl. In this case, it's where each line of a file ends up when you use the construction: while () { # each line of file in turn appears in $_ } You can find much more info on it in the perlvar manual page. Dave... -- Don't dream it... be it
Re: Update: Where to begin??!!??
Dave Cross wrote: > > > #! usr/bin/perl > > use strict; > > > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > > You don't check the result of opening the output file. I think, in general, that it is good programming practice that you check the opening of the output file. What if your input file inludes a bad path?
RE: Update: Where to begin??!!??
$_ is the default variable. It represents each line and assigns it to $_ . Actually, you don't even need it. You can try: split (/|/); greg --- Crystal Gruetzmacher <[EMAIL PROTECTED]> wrote: > what is $_ for? > > -Original Message- > From: Greg Meckes [mailto:[EMAIL PROTECTED]] > Sent: Friday, June 15, 2001 1:34 PM > To: Crystal Gruetzmacher; [EMAIL PROTECTED] > Subject: Re: Update: Where to begin??!!?? > > > First : > Your assigning a newline to the "$/" scalar: $/ = "\n"; > Why? Get rid of it. > > Second: > The split: split (/|/, $/); > Should be : split (/\|/, $_); > > Third: > You should escape the pipes in the print statement: > "$date|$time|$name|$street|etc"; > Should be: |$date\|$time\|$name\|$street\|etc"; > > Hope it helps along with my previous response. > > Greg > > > > > --- Crystal Gruetzmacher <[EMAIL PROTECTED]> wrote: > > I'm trying, really I am, but I can't get this thing to work (yet). Here's > > what I have so far. Am I missing something crucial that doesn't give an > > error message? > > > > #! usr/bin/perl > > use strict; > > > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > > open (FILE_OUT, ">pslbingocard.txt"); > > > > $/ = "\n"; > > > > while () { > > my ($date, $time, $name, $street, $city, $state, $zip, $country, $email, > > $phone, $submit, @subscriptions) = split (/|/, $/); > > # split each line on the > > pipe, and throw into matching > > # variable entries - note > > that bingo numbers are all > > # thrown into a single > > array. > > > > foreach my $subscription (@subscriptions) { # loop through the > > subscriptions array > > next unless $subscription +=0; # > > next unless $subscription =~/\s/; > > $subscription =~s/^\s+//; > > $subscription =~s/\s+$//; > > $new_data .= > > > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$phone|$subscri > > ption|\n"; # create a new line for each bingo number. > > } > > print FILE_OUT $new_data; > > } > > > > > > Crystal > > > > what I wrote before > > Hi all, > > > > I have a problem and I need to know where to begin. At the magazine I work > > for we have what are called "bingo cards" in the magazine that people can > > fill out and send back to us to get information on whatever of 271 topics, > > stores, resorts, etc. of their choice. They can also fill this out online. > > What we end up with is a DAT file with each users stuff as one entry in a > > pipe-delimited file with hard returns at the end of each entry. Of course > we > > could bring this into Excel or Access or some other DB, but the problem > then > > becomes that there are 283 fields. Not many DB's support that many. > > > > The point: > > I need to take this text file and format each entry (separated by hard > > returns) so that the user info (name address, etc) are all in their own > > columns still and then for each number they chose (up to 271 out of 271) > it > > creates a new entry with their contact info and one number in the last > > column. > > > > For example: Joe Smith|123 Main > > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would > > then become: > > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| > > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| > > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| > > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| > > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| > > > > Here is a sample entry from the DAT file. > > > > |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My > > > Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 > > > |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| > > > 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 > > > 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 > > > |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| > > > 109|110|111|112|113|114|115|
Re: Update: Where to begin??!!??
Crystal, Some comments interspersed with your code below. On Fri, Jun 15, 2001 at 01:25:59PM -0700, Crystal Gruetzmacher ([EMAIL PROTECTED]) wrote: > I'm trying, really I am, but I can't get this thing to work (yet). Here's > what I have so far. Am I missing something crucial that doesn't give an > error message? You're not using -w > #! usr/bin/perl > use strict; > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; You don't check the result of opening the output file. > open (FILE_OUT, ">pslbingocard.txt"); No need to set $/ as "\n" is its default value. > $/ = "\n"; > > while () { This is where the _real_ problems are. The pipe character has a special meaning in regular expressions, so you need to escape it with a backslash. Also you're splitting $/ (which only contains "\n") instead of $_ (which contains a line of data from your file). Try: split(/\|/, $_); or even just split(/\|/); as split works on $_ by default. > my ($date, $time, $name, $street, $city, $state, $zip, $country, $email, > $phone, $submit, @subscriptions) = split (/|/, $/); > # split each line on the > pipe, and throw into matching > # variable entries - note > that bingo numbers are all > # thrown into a single > array. > > foreach my $subscription (@subscriptions) { # loop through the > subscriptions array Not entirely sure what you mean this next line to do. What it actually does is add 0 to $subscription and then skip the rest of the loop if $subscription is false. > next unless $subscription +=0; # This say, skip the rest of the loop unless $subscription contains at least one whitespace character. Is that what you mean? > next unless $subscription =~/\s/; > $subscription =~s/^\s+//; > $subscription =~s/\s+$//; > > $new_data .= > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$phone|$subscri > ption|\n"; # create a new line for each bingo number. > } > print FILE_OUT $new_data; > } hth, Dave...
RE: Update: Where to begin??!!??
what is $_ for? -Original Message- From: Greg Meckes [mailto:[EMAIL PROTECTED]] Sent: Friday, June 15, 2001 1:34 PM To: Crystal Gruetzmacher; [EMAIL PROTECTED] Subject: Re: Update: Where to begin??!!?? First : Your assigning a newline to the "$/" scalar: $/ = "\n"; Why? Get rid of it. Second: The split: split (/|/, $/); Should be : split (/\|/, $_); Third: You should escape the pipes in the print statement: "$date|$time|$name|$street|etc"; Should be: |$date\|$time\|$name\|$street\|etc"; Hope it helps along with my previous response. Greg --- Crystal Gruetzmacher <[EMAIL PROTECTED]> wrote: > I'm trying, really I am, but I can't get this thing to work (yet). Here's > what I have so far. Am I missing something crucial that doesn't give an > error message? > > #! usr/bin/perl > use strict; > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > open (FILE_OUT, ">pslbingocard.txt"); > > $/ = "\n"; > > while () { > my ($date, $time, $name, $street, $city, $state, $zip, $country, $email, > $phone, $submit, @subscriptions) = split (/|/, $/); > # split each line on the > pipe, and throw into matching > # variable entries - note > that bingo numbers are all > # thrown into a single > array. > > foreach my $subscription (@subscriptions) { # loop through the > subscriptions array > next unless $subscription +=0; # > next unless $subscription =~/\s/; > $subscription =~s/^\s+//; > $subscription =~s/\s+$//; > $new_data .= > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$phone|$subscri > ption|\n"; # create a new line for each bingo number. > } > print FILE_OUT $new_data; > } > > > Crystal > > what I wrote before > Hi all, > > I have a problem and I need to know where to begin. At the magazine I work > for we have what are called "bingo cards" in the magazine that people can > fill out and send back to us to get information on whatever of 271 topics, > stores, resorts, etc. of their choice. They can also fill this out online. > What we end up with is a DAT file with each users stuff as one entry in a > pipe-delimited file with hard returns at the end of each entry. Of course we > could bring this into Excel or Access or some other DB, but the problem then > becomes that there are 283 fields. Not many DB's support that many. > > The point: > I need to take this text file and format each entry (separated by hard > returns) so that the user info (name address, etc) are all in their own > columns still and then for each number they chose (up to 271 out of 271) it > creates a new entry with their contact info and one number in the last > column. > > For example: Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would > then become: > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| > > Here is a sample entry from the DAT file. > > |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My > Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 > |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| > 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 > 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 > |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| > 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| > 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| > 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| > 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| > 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| > 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| > 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 > |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 > |262|263|264|265|266|267|268|269|270|271| > |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca > Valley|California|5|yugoslavia|[EMAIL PR
Re: Update: Where to begin??!!??
First : Your assigning a newline to the "$/" scalar: $/ = "\n"; Why? Get rid of it. Second: The split: split (/|/, $/); Should be : split (/\|/, $_); Third: You should escape the pipes in the print statement: "$date|$time|$name|$street|etc"; Should be: |$date\|$time\|$name\|$street\|etc"; Hope it helps along with my previous response. Greg --- Crystal Gruetzmacher <[EMAIL PROTECTED]> wrote: > I'm trying, really I am, but I can't get this thing to work (yet). Here's > what I have so far. Am I missing something crucial that doesn't give an > error message? > > #! usr/bin/perl > use strict; > > open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; > open (FILE_OUT, ">pslbingocard.txt"); > > $/ = "\n"; > > while () { > my ($date, $time, $name, $street, $city, $state, $zip, $country, $email, > $phone, $submit, @subscriptions) = split (/|/, $/); > # split each line on the > pipe, and throw into matching > # variable entries - note > that bingo numbers are all > # thrown into a single > array. > > foreach my $subscription (@subscriptions) { # loop through the > subscriptions array > next unless $subscription +=0; # > next unless $subscription =~/\s/; > $subscription =~s/^\s+//; > $subscription =~s/\s+$//; > $new_data .= > "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$phone|$subscri > ption|\n"; # create a new line for each bingo number. > } > print FILE_OUT $new_data; > } > > > Crystal > > what I wrote before > Hi all, > > I have a problem and I need to know where to begin. At the magazine I work > for we have what are called "bingo cards" in the magazine that people can > fill out and send back to us to get information on whatever of 271 topics, > stores, resorts, etc. of their choice. They can also fill this out online. > What we end up with is a DAT file with each users stuff as one entry in a > pipe-delimited file with hard returns at the end of each entry. Of course we > could bring this into Excel or Access or some other DB, but the problem then > becomes that there are 283 fields. Not many DB's support that many. > > The point: > I need to take this text file and format each entry (separated by hard > returns) so that the user info (name address, etc) are all in their own > columns still and then for each number they chose (up to 271 out of 271) it > creates a new entry with their contact info and one number in the last > column. > > For example: Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would > then become: > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| > Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| > > Here is a sample entry from the DAT file. > > |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My > Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 > |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| > 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 > 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 > |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| > 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| > 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| > 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| > 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| > 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| > 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| > 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 > |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 > |262|263|264|265|266|267|268|269|270|271| > |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca > Valley|California|5|yugoslavia|[EMAIL PROTECTED]|760-555-1212|Submit|| > |||53|58 > 78|||89||95||97| > |
Update: Where to begin??!!??
I'm trying, really I am, but I can't get this thing to work (yet). Here's what I have so far. Am I missing something crucial that doesn't give an error message? #! usr/bin/perl use strict; open (FILE_IN, "pslbingocard.dat")|| die "failed to open file\n"; open (FILE_OUT, ">pslbingocard.txt"); $/ = "\n"; while () { my ($date, $time, $name, $street, $city, $state, $zip, $country, $email, $phone, $submit, @subscriptions) = split (/|/, $/); # split each line on the pipe, and throw into matching # variable entries - note that bingo numbers are all # thrown into a single array. foreach my $subscription (@subscriptions) { # loop through the subscriptions array next unless $subscription +=0; # next unless $subscription =~/\s/; $subscription =~s/^\s+//; $subscription =~s/\s+$//; $new_data .= "$date|$time|$name|$street|$city|$state|$zip|$country|$email|$phone|$subscri ption|\n"; # create a new line for each bingo number. } print FILE_OUT $new_data; } Crystal what I wrote before**** Hi all, I have a problem and I need to know where to begin. At the magazine I work for we have what are called "bingo cards" in the magazine that people can fill out and send back to us to get information on whatever of 271 topics, stores, resorts, etc. of their choice. They can also fill this out online. What we end up with is a DAT file with each users stuff as one entry in a pipe-delimited file with hard returns at the end of each entry. Of course we could bring this into Excel or Access or some other DB, but the problem then becomes that there are 283 fields. Not many DB's support that many. The point: I need to take this text file and format each entry (separated by hard returns) so that the user info (name address, etc) are all in their own columns still and then for each number they chose (up to 271 out of 271) it creates a new entry with their contact info and one number in the last column. For example: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would then become: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| Here is a sample entry from the DAT file. |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 |262|263|264|265|266|267|268|269|270|271| |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca Valley|California|5|yugoslavia|[EMAIL PROTECTED]|760-555-1212|Submit|| |||53|58 78|||89||95||97| ||168||178186|||197| |207|||||||230|| I really need to know where to begin. Should I put everything between the first 12 pipes (including the pipes) into a variable and then run a loop on the remainder? Closet Geek >^..^<
Re: Where to begin??!!??
try: open(DAT, "file.dat") or die "Couldn't open the file: $!\n"; @DAT = ; close(DAT); #write to file open (OUT, ">out.dat") or die "Couldn't open the file: $!\n"; foreach my $Line(@DAT) { chomp $Line; #remove first pipe $Lines =~ s/\|//; my ($date,$time,$name,$street,$town,$state ,$zip,$country,$email,$phone,@nums) = split(/\|/,$Line); foreach my $Number(@nums) { if ($Number ne "") { #don't print lines without a number print "$name\|$street\|$town\|$country\|$zip\|$phone\|$email\|$Number\n"; # OR print to a file print OUT "$name\|$street\|$town\|$country\|$zip\|$phone\|$email\|$Number\n"; } } } close(OUT); __ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
Re: Where to begin??!!??
Just so I understand, you can't: ($date, $time, $add1, $add2, $add3, @rest) = split(/\|/); # can you? > @f = split(/\|/); # \| because | is a regexp char, splits $_ > > # grab the bits we want to duplicate for each record. you will have > # to tweak for the actual number of fields. @rest should just > contain > # the numbers > > ($date, $time, $add1, $add2, $add3, @rest) = @f; > > foreach $n (@rest) > { > $n =~ /^\s*$/ && next;# If the field is blank or space only > # ignore. =~ binds the pattern match > print "$date|$time|$add1|$add2|$add3|$n\n"; > } > } > > You can make this a bit more efficient but it would have been harder > to explain and wouldn't include some handy perlisms > > Enjoy, Steve > > Crystal Wrote... > > Hi all, > > I have a problem and I need to know where to begin. At the magazine I > work > for we have what are called "bingo cards" in the magazine that people > can > fill out and send back to us to get information on whatever of 271 > topics, > stores, resorts, etc. of their choice. They can also fill this out > online. > What we end up with is a DAT file with each users stuff as one entry > in > a > pipe-delimited file with hard returns at the end of each entry. Of > course we > could bring this into Excel or Access or some other DB, but the > problem > then > becomes that there are 283 fields. Not many DB's support that many. > > The point: > I need to take this text file and format each entry (separated by > hard > returns) so that the user info (name address, etc) are all in their > own > columns still and then for each number they chose (up to 271 out of > 271) > it > creates a new entry with their contact info and one number in the > last > column. > > For example: Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| > would > then become: > Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| > Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| > Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| > Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| > Joe Smith|123 Main > St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| > > Here is a sample entry from the DAT file. > > |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My > Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 > |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| > 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 > 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 > |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| > 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| > 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| > 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| > 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| > 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| > 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| > 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 > |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 > |262|263|264|265|266|267|268|269|270|271| > |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca > Valley|California|5|yugoslavia|[EMAIL PROTECTED]|760-555-1212|Submit|| > |||||||53|58 > 78|||89||95||97| > ||168||178186|||197| > |207|||230|| > > I really need to know where to begin. Should I put everything between > the > first 12 pipes (including the pipes) into a variable and then run a > loop > on > the remainder? > > Closet Geek >^..^< = - Notice: This e-mail is protected by the U.S. Constitution and the U.N. Declaration of Human Rights. Unauthorized interception by any public or private agency is an ugly sort of work to be in. Does your mother know you spend your days reading other people's mail? Would she be proud of you? - Please visit: http://clubs.yahoo.com/clubs/district41democrats __ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
Where to begin??!!??
Based on your input file format a|b|c|d|f|#|#|#... where letters are date, address etc, #'s are number and ... indicates lots more :-). # open file and complain if it failes open(F, "DAT") || die "failed to open DAT\n"; while () # read's into $_ by magic { @f = split(/\|/); # \| because | is a regexp char, splits $_ # grab the bits we want to duplicate for each record. you will have # to tweak for the actual number of fields. @rest should just contain # the numbers ($date, $time, $add1, $add2, $add3, @rest) = @f; foreach $n (@rest) { $n =~ /^\s*$/ && next; # If the field is blank or space only # ignore. =~ binds the pattern match print "$date|$time|$add1|$add2|$add3|$n\n"; } } You can make this a bit more efficient but it would have been harder to explain and wouldn't include some handy perlisms Enjoy, Steve Crystal Wrote... Hi all, I have a problem and I need to know where to begin. At the magazine I work for we have what are called "bingo cards" in the magazine that people can fill out and send back to us to get information on whatever of 271 topics, stores, resorts, etc. of their choice. They can also fill this out online. What we end up with is a DAT file with each users stuff as one entry in a pipe-delimited file with hard returns at the end of each entry. Of course we could bring this into Excel or Access or some other DB, but the problem then becomes that there are 283 fields. Not many DB's support that many. The point: I need to take this text file and format each entry (separated by hard returns) so that the user info (name address, etc) are all in their own columns still and then for each number they chose (up to 271 out of 271) it creates a new entry with their contact info and one number in the last column. For example: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would then become: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| Here is a sample entry from the DAT file. |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 |262|263|264|265|266|267|268|269|270|271| |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca Valley|California|5|yugoslavia|[EMAIL PROTECTED]|760-555-1212|Submit|| |||53|58 78|||89||95||97| ||168||178186|||197| |207|||230|||||||||| I really need to know where to begin. Should I put everything between the first 12 pipes (including the pipes) into a variable and then run a loop on the remainder? Closet Geek >^..^<
Re: Where to begin??!!??
>The point: >I need to take this text file and format each entry (separated by hard >returns) so that the user info (name address, etc) are all in their own >columns still and then for each number they chose (up to 271 out of 271) it >creates a new entry with their contact info and one number in the last >column. Here's some untested pseudo code to help you: # for each line of the DAT file: while () { # split each line on the pipe, and throw into matching # variable entries - note that bingo numbers are all # thrown into a single array. my ($date, $time, $name, $street, $city, $state, $town, $zip, $country, $email, $phone, @subscriptions) = split (/|/, $_); # now, loop through the subscriptions array and # create a new line for each bingo number. foreach my $subscription (@subscriptions) { $new_data .= "$name|$street|$city|$state|$country| $zip|$phone|$email|$subscription|\n"; } } Once the entire DAT file has been looped through, you'll have your completed data in $new_data to do whatever you want. NOTE that this is untested code. Don't sue me if I birth your child. Morbus Iff .sig on other machine. http://www.disobey.com/ http://www.gamegrene.com/
Where to begin??!!??
Hi all, I have a problem and I need to know where to begin. At the magazine I work for we have what are called "bingo cards" in the magazine that people can fill out and send back to us to get information on whatever of 271 topics, stores, resorts, etc. of their choice. They can also fill this out online. What we end up with is a DAT file with each users stuff as one entry in a pipe-delimited file with hard returns at the end of each entry. Of course we could bring this into Excel or Access or some other DB, but the problem then becomes that there are 283 fields. Not many DB's support that many. The point: I need to take this text file and format each entry (separated by hard returns) so that the user info (name address, etc) are all in their own columns still and then for each number they chose (up to 271 out of 271) it creates a new entry with their contact info and one number in the last column. For example: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1|2||8||10|11| would then become: Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|1| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|2| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|8| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|10| Joe Smith|123 Main St.|Yourtown|US|83124|888-555-1212|[EMAIL PROTECTED]|11| Here is a sample entry from the DAT file. |6/12/2001|13:05:34|Closet Geek|456 Flibity Jibet Way|My Town|CA|90450|US|[EMAIL PROTECTED]|760-555-1212||1|2|3|4|5|6|7|8|9|10 |11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| 36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|6 1|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86 |87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108| 109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127| 128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146| 147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165| 166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184| 185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203| 204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222| 223|224|225|226|227|228|229|230|231|232||234|235|236|237|238|239|240|241|242 |243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261 |262|263|264|265|266|267|268|269|270|271| |6/12/2001|13:14:42|closetgeek|456 Flibity Jibet Way|Yucca Valley|California|5|yugoslavia|[EMAIL PROTECTED]|760-555-1212|Submit|| |||53|58 78|||89||95||97| ||168||178186|||197| |207|||230|| I really need to know where to begin. Should I put everything between the first 12 pipes (including the pipes) into a variable and then run a loop on the remainder? Closet Geek >^..^<