CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
need a solution or logic

 



perl_newbie10
New User

Jan 2, 2009, 2:48 AM

Post #1 of 2 (1820 views)
need a solution or logic Can't Post

Hi,

I have orginal text file like this:

orange, 10, 20, 30.
apple banana, 20, 30, 40.

I wanted the the original text file to be rewritten as:

orange, 10
orange, 20
orange, 30
apple banana, 20
apple banana, 30
apple banana, 40

using perl and regular expression.
If any solutions or suggestions would be nice and very much appreciated.

many thanks

newbie.


shawnhcorey
Enthusiast


Jan 2, 2009, 6:03 AM

Post #2 of 2 (1818 views)
Re: [perl_newbie10] need a solution or logic [In reply to] Can't Post


In Reply To
Hi,

I have orginal text file like this:

orange, 10, 20, 30.
apple banana, 20, 30, 40.

I wanted the the original text file to be rewritten as:

orange, 10
orange, 20
orange, 30
apple banana, 20
apple banana, 30
apple banana, 40

using perl and regular expression.
If any solutions or suggestions would be nice and very much appreciated.

many thanks

newbie.



Code
my ( $fruit, @amount ) = split /\s*,\s*/, $_; 
for my $amount ( @amount ){
print "$fruit, $amount\n";
}


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives