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

Re: Re: Check tag value

by Anonymous Monk
on Apr 08, 2004 at 11:51 UTC ( #343584=note: print w/replies, xml ) Need Help??

in reply to Re: Check tag value
in thread Check tag value

This is what I have so far ..I am still working on it #!/usr/bin/perl my $dir = "/tmp/asheesh"; my gdir = "$dir/temp"; opendir (DIR, $dir) or die "can't open dir"; @files = readdir(DIR); closedir DIR; foreach $files(@files) { unless ( $files eq "." || $files eq "..") { open (FILE, "$files") or die "can't open file"; @Lines=<FILE>; close FILE; foreach $Lines(@Lines) { chomp $Lines; if ( $Lines eq "<NumberofDays>\d+</NumberofDays>" )

Replies are listed 'Best First'.
Re: Re: Re: Check tag value
by eXile (Priest) on Apr 08, 2004 at 15:09 UTC
    Hi, you're code:
    if ( $Lines eq "<NumberofDays>\d+</NumberofDays>" )
    should be something like:
    if ( $Lines =~ m|<NumberofDays>(\d+)</NumberofDays>| )
    3 differences between your and my line:
    • eq vs. =~
    • to compare against a regular expression you use =~
    • the regular expression is in 'm|' and '|' characters
    • This is to make clear you are using a regular expression
    • the \d+ is in '(' and ')' characters
    • This is used to 'capture' the value of the expression inbetween them. In this case it would capture the value in $1. The rule is the first ()-match is captured in $1, the second in $2 etc. So in your code you could continue with something like
      print $1
    Hope this helps getting you started. For documentation on regular expressions there are 2 good tutorials that come with perl that were not mentioned here: perlrequick perlretut
Re: Re: Re: Check tag value
by hmerrill (Friar) on Apr 08, 2004 at 12:01 UTC
    You need a regular expression in your if-test. Start by doing:
    perldoc perl
    at a command prompt. You'll notice if you page down a little that there are these 2 perldocs listed for regular expressions:
    perlre Perl regular expressions, the rest of the story perlreref Perl regular expressions quick reference
    So, if you want to read the 1st one, you would do
    perldoc perlre
    at a command prompt. The 1st response to your question gave you a regular expression to try. Read the perldocs, try a regular expression, and post back if you still have problems.


      I have no clue about perl ..thanks for your direction
      I can't seem to use perldoc
        What platform are you on?

        Besides accessing the perldocs on your own machine, which you seem to be having trouble with, you can also access the perdocs online at Here is the link for 'perlre':


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2023-06-05 00:50 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.