Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Laurent_R (Vicar)
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; # ... }


Comment on Re: Code that copy's multiple times a $ from a document
Download Code
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
      #!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
      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-08-22 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (153 votes), past polls