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

RAM, "

by Laurent_R (Canon)
on Nov 22, 2014 at 21:40 UTC ( [id://1108125]=note: print w/replies, xml ) Need Help??


in reply to Make a perl script by taking specific lines from a txt file

I have no idea about what lemur is, and also don't know what IndriRunQuery is, but you could possibly do something like this;
for my $i (351..354) { my $param = "<parameters> <index>/home/nikol123/indri-5.6/4collections</index> <query> <type>indri</type> <number>$i</number> <text>British Chunnel i +mpact</text> </query> <fbDocs>10</fbDocs> </parameters>"; my $paramfile = "param$i.txt"; open my $PARAM, ">", $paramfile or die "Can't open $paramfile $ +!"; print $PARAM, $param; close $PARAM; do_something_with($paramfile); }

Replies are listed 'Best First'.
Re: RAM, "
by karlgoethebier (Abbot) on Nov 22, 2014 at 23:57 UTC
    "I have no idea about what lemur is..."

    Please see Lemur as well as The Lemur Project ;-)

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Thank you, Karl. I actually knew what lemurs were (the animals), but had not idea about what the Lemur Project was.

        karlgoethebier has cleared things up a little bit, but I still don't understand the Perl question implicit in nimpoura's OP.

        Actually, I, too, have a problem that is really urgent! I would like to live a good life! I am working with the crappy life I currently live. Thank you in advance for any advice!

Re: RAM, "
by Anonymous Monk on Nov 23, 2014 at 18:19 UTC
    I wrote this code :
    #!/usr/bin/perl use strict; use warnings; for(my $i=351; $i<400; $i++){ my $filename = '/home/nikol123/indri-5.6/runquery/trec7_4collections.t +xt'; open(my $file, '<', $filename) or die "open: $!"; while ( <$file> ) { my @lines = split(/\n/, $filename); foreach my $line (@lines) { if ($line = '<query> <type>indri</type> <number>$i</number> <text>"_" +</text> </query>') { my $param = "<parameters> <index>/home/nikol123/indri-5.6/4collections</index> print $line; <fbDocs>10</fbDocs> </parameters>"; print $param; }}}}
    but it's not functional as i get this
    <parameters> <index>/home/nikol123/indri-5.6/4collections</index> print <query> <type>indri</type> <number>$i</number> <text>"_"</text> +</query>; <fbDocs>10</fbDocs> </parameters>
    but i want due to for loop to read and write the line that contain the variable i from the my txt file ,in order to have the according text field, for example for i=351 to have
    <parameters> <index>/home/nikol123/indri-5.6/4collections</index> <query> <type>indri</type> <number>351</number> <text>Falkland petrole +um exploration</text> </query>; <fbDocs>10</fbDocs> </parameters>
      Consider using an XML parser. eg XML:Twig.
      #!perl use strict; use warnings; use XML::Twig; my $filename = 'trec7_4collections.txt'; our $num; my $fh; for $num (351..354){ open $fh,'>',$num.'.xml' or die "$!"; my $twig = XML::Twig->new( twig_handlers => { query => \&query }, pretty_print=>'indented' ); $twig->parsefile($filename); $twig->flush($fh); print "Created $num.xml\n"; } sub query { my( $twig, $e) = @_; my $n = $e->first_child_text('number'); $e->cut if ($n ne $num); }
      poj

Log In?
Username:
Password:

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

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

    No recent polls found