Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Accessing data between two tags

by prasadbabu (Prior)
on Nov 09, 2006 at 11:21 UTC ( #583084=note: print w/replies, xml ) Need Help??


in reply to Accessing data between two tags

Hi ant,

Are you looking something like this?

my (@value) = $line =~ m|<CS_REFCLT>(\d+)</CS_REFCLT>|g; or my (@value) = $line =~ m|<CS_REFCLT>((?:(?!</CS_REFCLT>).)*)</CS_REFCL +T>|g;

Also take a look at perlre.

Prasad

Replies are listed 'Best First'.
Re^2: Accessing data between two tags
by johngg (Canon) on Nov 09, 2006 at 11:53 UTC
    ITYM my ($value) = $line =~ m|<CS_REFCLT>(\d+)</CS_REFCLT>|g; as you are trying to pull out a scalar not an array.

    Cheers,

    JohnGG

      johngg,

      I am getting array as output. As per your solution, we can get only one value even if you use 'g' modifier.

      use strict; use warnings; my $line = 'some text <CS_REFCLT>12121</CS_REFCLT> then some text <CS_ +REFCLT>4654</CS_REFCLT> here'; my (@value) = $line =~ m|<CS_REFCLT>(\d+)</CS_REFCLT>|g; my ($value) = $line =~ m|<CS_REFCLT>(\d+)</CS_REFCLT>|g; $" ="\t"; print "Array: @value\n"; print "Scalar: $value\n"; prints: ------- Array: 12121 4654 Scalar: 12121

      Prasad

        Reading the OP, I'm pretty sure pulling out a scalar is what ant wants to do. It firstly says that the file is large, about a gigabyte, so you are most likely to process the file a line at a time rather than slurp it into memory. It goes on to say

        each line has <CS_REFCLT>12526489</CS_REFCLT> in it some where

        which I take to mean just one occurance of the string per line, not multiples. Note also that ant says "I can't use substr to get at it." That strongly reinforces my interpretation.

        Of course, my interpretation could be totally wrong :)

        Cheers,

        JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2023-12-10 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?