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

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

by Laurent_R (Abbot)
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]
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-06-22 12:36 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.