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

Re: Check tag value

by esskar (Deacon)
on Apr 08, 2004 at 11:38 UTC ( [id://343581]=note: print w/replies, xml ) Need Help??


in reply to Check tag value

well, the parsing would be
m!<NumberofDays>\d+</NumberofDays>!gm;
but i belive in Learning By Doing, so why don't u post what you have tried so far solving your problem and we will help you moving you into the right direction.

bye, bye!

Replies are listed 'Best First'.
Re: Re: Check tag value
by Anonymous Monk on Apr 08, 2004 at 11:51 UTC
    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>" )
      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
      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.

      HTH.

        I have no clue about perl ..thanks for your direction
        I can't seem to use perldoc

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found