Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Code that copy's multiple times a $ from a document

by Waterdrake (Initiate)
on May 21, 2014 at 17:59 UTC ( [id://1087010]=note: print w/replies, xml ) Need Help??


in reply to Re: Code that copy's multiple times a $ from a document
in thread Code that copy's multiple times a $ from a document

i just need to copy the sequences what i mean by that i have a sequence and before it a number. this number corresponds to how many times i need the sequence to be copied. again an example but whit fruits because its easier
2 apples i need it to write 1-1 -> apple 1-2 -> apple
and then do the same whit other fruits in the list and save them in a txt document

Replies are listed 'Best First'.
Re^3: Code that copy's multiple times a $ from a document
by GotToBTru (Prior) on May 21, 2014 at 20:35 UTC
    use strict; use warnings; my $sc = 1; while (<DATA>) { my (undef,$repeat,$seq) = split /\s+/,$_; my $i = 1; while ($repeat--) { printf "%d-%d %s\n",$sc,$i++,$seq; } $sc += 1; } __DATA__ 1 2 tt 2 3 aa 3 1 dd

    Output

    1-1 tt 1-2 tt 2-1 aa 2-2 aa 2-3 aa 3-1 dd
    1 Peter 4:10
      Thank you very much.
Re^3: Code that copy's multiple times a $ from a document
by poj (Abbot) on May 21, 2014 at 19:50 UTC
    #!perl use strict; use warnings; open FH, '<', 'filename.txt' or die $!; open FHWRITE, '>>','results.txt' or die $!; my $count; while (my $line = <FH>){ print $line; my ($i,$repeat,$seq) = split /\s+/, $line; print FHWRITE "$i-$_ $seq\n" for (1..$repeat); $count += $repeat; } print "\n$count records written to results.txt\n";
    poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found