Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

by Laurent_R (Canon)
on May 21, 2014 at 17:48 UTC ( #1087008=note: print w/replies, xml ) Need Help??

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

I did not quite understand what you need to do with your data (your example does not seem to correspond with your textual description), but to get the values you need into variables, you might use this:
#!/usr/bin/perl\ use strict; use warnings; open my $FH "<", "filename.txt" or die $!; while (my $line = <$FH>) { my ($id, number, $sequence) = split /\s+/, $line; # ... }

Replies are listed 'Best First'.
Re^2: Code that copy's multiple times a $ from a document
by Waterdrake (Initiate) on May 21, 2014 at 17:59 UTC
    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
      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


      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.
      #!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";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1087008]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-01-20 19:59 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.