Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
[1nickt]: Config works properly, thank you. I has first followed an example from the doc using eval. THis is much nicer.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-10-18 15:41 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (249 votes). Check out past polls.