[23826] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6029 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 21:16:27 2004

Date: Thu, 29 Jan 2004 18:11:01 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 29 Jan 2004     Volume: 10 Number: 6029

Today's topics:
        pattern matching and grabing value sub (J M)
    Re: pattern matching and grabing value sub <tadmc@augustmail.com>
    Re: pattern matching and grabing value sub <noone@nowhere.com>
    Re: pattern matching and grabing value sub <gnari@simnet.is>
    Re: pattern matching and grabing value sub <JM@jm.biz>
    Re: pattern matching and grabing value sub <robin@csf.edu>
    Re: pattern matching and grabing value sub <JM@jm.biz>
    Re: pattern matching and grabing value sub (Walter Roberson)
    Re: pattern matching and grabing value sub <JM@jm.biz>
    Re: pattern matching and grabing value sub (Walter Roberson)
    Re: pattern matching and grabing value sub <gnari@simnet.is>
    Re: pattern matching and grabing value sub (Anno Siegel)
    Re: pattern matching and grabing value sub <tadmc@augustmail.com>
    Re: pattern matching and grabing value sub (G Klinedinst)
    Re: pattern matching and grabing value sub <Joe.Smith@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 22 Jan 2004 12:42:31 -0800
From: jagman98@attbi.com (J M)
Subject: pattern matching and grabing value sub
Message-Id: <4a8adfa4.0401221242.626b7266@posting.google.com>

I have a postscript file with follwing information

more lines.....
s1 w1 (Queue Number) w2 s2
1954 7483 mt
sapf1 sf
(1234567890) s
80 su
1714 9694 mt
sapf2 sf
44 sw
s1 w1 (Queue Date) w2 s2
more lines.....

How can I pattern match for "Queue Number" and "Queue Date" and grep
1234567890.  Both Queue Number and Queue Date are static values.

The return value for sub I am trying to get is 1234567890 without
brackets.

TIA!


------------------------------

Date: Thu, 22 Jan 2004 16:10:02 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: pattern matching and grabing value sub
Message-Id: <slrnc10ihq.b55.tadmc@magna.augustmail.com>

J M <jagman98@attbi.com> wrote:
> I have a postscript file with follwing information
> 
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
> 
> How can I pattern match for "Queue Number" 

   /Queue Number/

> and "Queue Date" 

   /Queue Date/

> and grep
> 1234567890. 

   my($num) = grep /1234567890/, @lines;


> The return value for sub I am trying to get is 1234567890 without
> brackets.


Hmmm. I don't see how any of your earlier questions will help solve
that problem.

But _why_ is 1234567890 the thing that should be returned?

What distinguishes it from the parts you don't want?


If you can give a clear Requirements Specification, then someone
can surely show you how to do it in Perl.


use PSI::ESP;

Q:
   How can I return the contents of the first parens that do not
   contain "Queue Number" or "Queue Date"?

A:
   while ( $ps =~ /\(([^)]*)\)/g ) {
      next if $1 eq 'Queue Number' or $1 eq 'Queue Date';
      print "matched '$1'\n";
   }

or, better:

   while ( $ps =~ /  \(  (  [^)]*  )  \)  /xg ) {


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 22 Jan 2004 22:38:23 GMT
From: "gibbering poster" <noone@nowhere.com>
Subject: Re: pattern matching and grabing value sub
Message-Id: <zhYPb.14738$ng1.2529@newssvr27.news.prodigy.com>


"J M" <jagman98@attbi.com> wrote in message
news:4a8adfa4.0401221242.626b7266@posting.google.com...
> I have a postscript file with follwing information
>
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
>
> How can I pattern match for "Queue Number" and "Queue Date" and grep
> 1234567890.  Both Queue Number and Queue Date are static values.
>
> The return value for sub I am trying to get is 1234567890 without
> brackets.
>
> TIA!

Note sure what the real requirements of your search are, but something
like this (untested) should get you by:

print $1 if /Queue Number.*?\((\d+)\).*?Queue Date/s;




------------------------------

Date: Thu, 22 Jan 2004 22:35:25 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: pattern matching and grabing value sub
Message-Id: <bupjct$4mc$1@news.simnet.is>

"J M" <jagman98@attbi.com> wrote in message
news:4a8adfa4.0401221242.626b7266@posting.google.com...
> I have a postscript file with follwing information
>
[snipped a few lines of postscript that need to be matched]
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
>
> How can I pattern match for "Queue Number" and "Queue Date" and grep
> 1234567890.  Both Queue Number and Queue Date are static values.
>

You omit to say what you have tried, and why it failed.

as this is postscript, and likely to be large, I will not suggest
slurping and using m//s

you might just want to loop-read lines of the file
until /Queue Number/, then read more lines until
/(\d+)\s+s/

gnari






------------------------------

Date: Fri, 23 Jan 2004 00:13:17 GMT
From: "J M" <JM@jm.biz>
Subject: Re: pattern matching and grabing value sub
Message-Id: <xGZPb.7699$Ls3.3714@newssvr24.news.prodigy.com>

The 1234567890 is a random number.

Thanks!

"J M" <jagman98@attbi.com> wrote in message
news:4a8adfa4.0401221242.626b7266@posting.google.com...
> I have a postscript file with follwing information
>
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
>
> How can I pattern match for "Queue Number" and "Queue Date" and grep
> 1234567890.  Both Queue Number and Queue Date are static values.
>
> The return value for sub I am trying to get is 1234567890 without
> brackets.
>
> TIA!




------------------------------

Date: Thu, 22 Jan 2004 15:46:34 -0700
From: "Robin" <robin@csf.edu>
Subject: Re: pattern matching and grabing value sub
Message-Id: <bupvup$9er$1@reader2.nmix.net>

use this /mathch|match2/, the pipe "|" is used as an "or" operator for
matches.

--
Regards,
Robin
--
robin@csf.edu
--

"J M" <jagman98@attbi.com> wrote in message
news:4a8adfa4.0401221242.626b7266@posting.google.com...
> I have a postscript file with follwing information
>
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
>
> How can I pattern match for "Queue Number" and "Queue Date" and grep
> 1234567890.  Both Queue Number and Queue Date are static values.
>
> The return value for sub I am trying to get is 1234567890 without
> brackets.
>
> TIA!




------------------------------

Date: Fri, 23 Jan 2004 03:23:42 GMT
From: "J M" <JM@jm.biz>
Subject: Re: pattern matching and grabing value sub
Message-Id: <2t0Qb.7722$DA4.1220@newssvr24.news.prodigy.com>

I am going to rephrase this request:

How can I grab dynamic digit value (for in this example 1234567890) between
"Queue Number" and "Queue Date" static keys?  So I have to find
"(NNNNNNNNN)" value that is in a line between (Queue Number) and (Queue
Date).

> I have a postscript file with follwing information
>
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines.....
>
> How can I pattern match for "Queue Number" and "Queue Date" and grep
> 1234567890.  Both Queue Number and Queue Date are static values.
>
> The return value for sub I am trying to get a dynamic value (digits in
brackets) 1234567890 without brackets.
>
> TIA!




------------------------------

Date: 23 Jan 2004 03:37:50 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: pattern matching and grabing value sub
Message-Id: <buq4ue$bjo$1@canopus.cc.umanitoba.ca>

In article <2t0Qb.7722$DA4.1220@newssvr24.news.prodigy.com>,
J M <JM@jm.biz> wrote:
:I am going to rephrase this request:

:How can I grab dynamic digit value (for in this example 1234567890) between
:"Queue Number" and "Queue Date" static keys?  So I have to find
:"(NNNNNNNNN)" value that is in a line between (Queue Number) and (Queue
:Date).

:> I have a postscript file with follwing information


:> s1 w1 (Queue Number) w2 s2
:> 1954 7483 mt
:> sapf1 sf
:> (1234567890) s
:> 80 su
:> 1714 9694 mt
:> sapf2 sf
:> 44 sw
:> s1 w1 (Queue Date) w2 s2

local $\; $_ = <>;   #slurp the whole file

@Qnos = m/Queue Number\.*\((\d+)\).*Queue Date/sg;  #match what you want
-- 
Caution: A subset of the statements in this message may be
tautologically true.


------------------------------

Date: Fri, 23 Jan 2004 05:03:12 GMT
From: "J M" <JM@jm.biz>
Subject: Re: pattern matching and grabing value sub
Message-Id: <kW1Qb.10761$Yz5.4990@newssvr23.news.prodigy.com>

Sounds like the special characters and spaces in PS file causing major
problem for me:

#!/usr/bin/perl

$PSF='/my/test.ps';

open(PSFI, "$PSF") || writeLog("$PSF open failed!");

@pslines = <PSFI>;

close(PSFI);

@pslines =~  tr\-_/A-Za-z0-9##cd;

@pslines = m/Queue\ Number\.*\((\d+)\).*Queue\ Date/sg;

print "$pslines";



=============================================================

syntax error at get-queue-num.pl line 10, near "@pslines = m/Queue
Number\.*\("

Backslash found where operator expected at get-queue-num.pl line 10, near
")\"

        (Missing operator before \?)

Bareword found where operator expected at get-queue-num.pl line 10, near
"*Queue Date"

        (Missing operator before Date?)

syntax error at get-queue-num.pl line 14, at EOF

Execution of get-queue-num.pl aborted due to compilation errors.

=======================================================================

"J M" <JM@jm.biz> wrote in message
news:xGZPb.7699$Ls3.3714@newssvr24.news.prodigy.com...
> The 1234567890 is a random number.
>
> Thanks!
>
> "J M" <jagman98@attbi.com> wrote in message
> news:4a8adfa4.0401221242.626b7266@posting.google.com...
> > I have a postscript file with follwing information
> >
> > more lines.....
> > s1 w1 (Queue Number) w2 s2
> > 1954 7483 mt
> > sapf1 sf
> > (1234567890) s
> > 80 su
> > 1714 9694 mt
> > sapf2 sf
> > 44 sw
> > s1 w1 (Queue Date) w2 s2
> > more lines.....
> >
> > How can I pattern match for "Queue Number" and "Queue Date" and grep
> > 1234567890.  Both Queue Number and Queue Date are static values.
> >
> > The return value for sub I am trying to get is 1234567890 without
> > brackets.
> >
> > TIA!
>
>




------------------------------

Date: 23 Jan 2004 05:50:39 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: pattern matching and grabing value sub
Message-Id: <buqcnf$et5$1@canopus.cc.umanitoba.ca>

In article <kW1Qb.10761$Yz5.4990@newssvr23.news.prodigy.com>,
J M <JM@jm.biz> wrote:
:Sounds like the special characters and spaces in PS file causing major
:problem for me:

:@pslines =~  tr\-_/A-Za-z0-9##cd;

You are attempting to use backslash as the pattern delimeter for
tr, but you don't match the backslash until a later line.

You didn't  use warnings;   neh?


:@pslines = m/Queue\ Number\.*\((\d+)\).*Queue\ Date/sg;

@pslines = m/Queue Number.*\((\d+)\).*Queue Date/sg;

There is no reason to backslash the space, and you definitely don't
want to backslash the period.
-- 
   "The human genome is powerless in the face of chocolate."
   -- Dr. Adam Drewnowski


------------------------------

Date: Fri, 23 Jan 2004 08:29:55 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: pattern matching and grabing value sub
Message-Id: <buqm7k$9t1$1@news.simnet.is>

"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message
news:buq4ue$bjo$1@canopus.cc.umanitoba.ca...
> In article <2t0Qb.7722$DA4.1220@newssvr24.news.prodigy.com>,
> J M <JM@jm.biz> wrote:
> :I am going to rephrase this request:

[snipped request that i think most of us got the first time]

> local $\; $_ = <>;   #slurp the whole file

I just hope your postscript file does get too large

>
> @Qnos = m/Queue Number\.*\((\d+)\).*Queue Date/sg;  #match what you want

apart from the fact that you have a quoted perion after 'Number', this will
only
work as long as there is only one such item in the file. consider:
Queue Number (123) Queue Date  (abc) Queue Number (124) Queue Date

I suggest (untested), if many occurances to be found:
@Qnos = m/Queue Number.*?\((\d+)\).*?Queue Date/sg;  #match what you want

or if only one to be found:
($num) = m/Queue Number.*?\((\d+)\).*?Queue Date/s;  #match what you want

gnari





------------------------------

Date: 23 Jan 2004 11:41:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: pattern matching and grabing value sub
Message-Id: <bur18j$dk$1@mamenchi.zrz.TU-Berlin.DE>

Robin <robin@csf.edu> wrote in comp.lang.perl.misc:

> use this /mathch|match2/, the pipe "|" is used as an "or" operator for
> matches.

Top-posting some sloppily spelled Perl-like drivel that has nothing to do
with the question isn't going to win you points.

[snip fullquote]

Anno


------------------------------

Date: Thu, 22 Jan 2004 23:26:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: pattern matching and grabing value sub
Message-Id: <slrnc11c4i.1fb.tadmc@magna.augustmail.com>


[ Please do not top-post. ]


J M <JM@jm.biz> wrote:

> #!/usr/bin/perl

You should ask for all of the help that you can get:

   use strict;
   use warnings;


> $PSF='/my/test.ps';
> 
> open(PSFI, "$PSF") || writeLog("$PSF open failed!");
             ^    ^
             ^    ^ a useless use of double quotes

Let's fix that, and work the value of $! into the function call:

   open(PSFI, $PSF) || writeLog("$PSF open failed!  $!");


> @pslines = <PSFI>;
> 
> close(PSFI);
> 
> @pslines =~  tr\-_/A-Za-z0-9##cd;
> 
> @pslines = m/Queue\ Number\.*\((\d+)\).*Queue\ Date/sg;
> 
> print "$pslines";
> 
> 
> 
>=============================================================
> 
> syntax error at get-queue-num.pl line 10, near "@pslines = m/Queue


Remove one line at a time from your program, and re-run it.

If the problem is still there put that line back in, and
remove the next line, run it again.

When the problem goes away, look closely at the line you just
deleted (you _are_ keeping backups, aren't you?).

Fix the syntax error in that line. All better.



[ snip upside-down quoted text ]

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 23 Jan 2004 12:50:51 -0800
From: g_klinedinst@hotmail.com (G Klinedinst)
Subject: Re: pattern matching and grabing value sub
Message-Id: <168f035a.0401231250.11cb4b7d@posting.google.com>

"J M" <JM@jm.biz> wrote in message news:<kW1Qb.10761

> Sounds like the special characters and spaces in PS file causing major

[snip]

> =============================================================
> 
> syntax error at get-queue-num.pl line 10, near "@pslines = m/Queue
> Number\.*\("
> 
> Backslash found where operator expected at get-queue-num.pl line 10, near
> ")\"
> 
>         (Missing operator before \?)
> 
> Bareword found where operator expected at get-queue-num.pl line 10, near
> "*Queue Date"
> 
>         (Missing operator before Date?)
> 
> syntax error at get-queue-num.pl line 14, at EOF
> 
> Execution of get-queue-num.pl aborted due to compilation errors.
> 
> =======================================================================

I am by no means an expert unlike many of the people here, who have
already given you some great solutions. I will however recommend, as
one student to another, that you use "perl -c" on your scripts before
trying to run them, to check your syntax. Your comment indicates you
think the problem is with the datafile, not the code, but you would
know for sure that wasn't the case if you tried to check the syntax
first. I use it on everything I write, including "-w" and "use strict"
and all of those tools help immensely.

BTW, are we to assume that there are no nested examples of what you
are searching for? Just curious b/c I was going to write my own
solution and post it up here to get sliced and diced, oops, I mean
constructively criticized.

-Greg


------------------------------

Date: Mon, 26 Jan 2004 06:10:00 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: pattern matching and grabing value sub
Message-Id: <Ya2Rb.119354$5V2.620466@attbi_s53>

Joe Smith wrote:

> J M wrote:
> 
>> I am going to rephrase this request:
>>
>> How can I grab dynamic digit value (for in this example 1234567890) 
>> between
>> "Queue Number" and "Queue Date" static keys?  So I have to find
>> "(NNNNNNNNN)" value that is in a line between (Queue Number) and (Queue
>> Date).
> 
> 
> Have you checked the ".." operator?
> 
>        Range Operators
> 
>  Binary ".." is the range operator, which is really two different
>  operators depending on the context.  In scalar context, ".." returns
>  a boolean value.  The operator is bistable, like a flip-flop, and
>  emulates the line-range (comma) operator of sed, awk, and various
>  editors.
> 
> jms@mathras> cat temp
> more lines.....
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (1234567890) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines...
> more lines...
> s1 w1 (Queue Number) w2 s2
> 1954 7483 mt
> sapf1 sf
> (9876543210) s
> 80 su
> 1714 9694 mt
> sapf2 sf
> 44 sw
> s1 w1 (Queue Date) w2 s2
> more lines...
> 
> mathras> perl temp.pl temp
> Found number 1234567890 at line 5
> Found number 9876543210 at line 16

Oops.  Forgot to include the code.

mathras> cat temp.pl
while(<>) {
   if (/\(Queue Number\)/ .. /\(Queue Date\)/) {
     print "Found number $1 at line $.\n" if /\((\d+)\)/;
   }
}


-Joe

-- 
I love my TiVo - http://www.inwap.com/u/joe/tivo/


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6029
***************************************


home help back first fref pref prev next nref lref last post