[22916] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5136 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 25 21:05:52 2003

Date: Wed, 25 Jun 2003 18:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 25 Jun 2003     Volume: 10 Number: 5136

Today's topics:
        Array dereferencing (Jan Fure)
    Re: Array dereferencing (Jay Tilton)
    Re: Array dereferencing <jkeen@concentric.net>
    Re: ASN1.pm example required (Torsten Drees)
        Checking if a method is defined in perl 5.00503 (Aaron Brice)
    Re: Checking if a method is defined in perl 5.00503 (Tad McClellan)
    Re: Checking if a method is defined in perl 5.00503 <ndronen@io.frii.com>
    Re: Database Connection Pooling in Perl CGI Script WITH ctcgag@hotmail.com
    Re: how to convert all invalid UTF-8 sequences to numer <flavell@mail.cern.ch>
    Re: Looking for inspiration: cascading CGI <emschwar@pobox.com>
    Re: Oracle CLOB using DBI <r_reidy@comcast.net>
    Re: Perl & HTTP <ed.murray@attbi.com>
        perl memory management - does @array = () free the memo (Matt Oefinger)
    Re: perl memory management - does @array = () free the  <ndronen@io.frii.com>
    Re: problem of backslash conversion with MKS perl (Dozy Choi)
    Re: Quick Q about $| <REMOVEsdnCAPS@comcast.net>
    Re: search for messages in large files <james.mctiernan@rcn.com>
    Re: search for messages in large files <mgjv@tradingpost.com.au>
        system("clear"); vs. system("cls"); <lbl@pbzpnfg.arg>
    Re: system("clear"); vs. system("cls"); <kkeller-spammmm@wombat.san-francisco.ca.us>
    Re: system("clear"); vs. system("cls"); (Tad McClellan)
    Re: Using Formats and stopping between pages <r_reidy@comcast.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Jun 2003 12:30:37 -0700
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Array dereferencing
Message-Id: <e47a84bf.0306251130.a70d5c9@posting.google.com>

Hi;

I the code below, I am creating a data structure of array references.
I want to loop through the keys, and for each key, which corresponds
to multiple values, I want to dereference the data to get a plain
array containing the values. I have read 'perlref', but it is still
not clear to me.

I made the code based on the 'Hashes with Multiple Values Per Key'
from the Perl Coocbook, and also inspired by some posts to this group.

I used Data::Dumper to see that I have the right data.

	my %data;
	for $row ( @DATA2 ){ #@DATA2 is an array of arrays
		push @{ $data{$$row[0]} }, $$row[1];
	}
	my @points;
  	foreach ( sort { $a <=> $b } keys %data ) {
      	@{$data{$_}} = sort { $a <=> $b } @{$data{$_}};
      	push @{$points[0]}, $_;
      	push @{$points[1]}, $data{$_};
  	}


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

Date: Wed, 25 Jun 2003 22:20:09 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Array dereferencing
Message-Id: <3efa1fdf.338871560@news.erols.com>

jan_may2002_fure@attbi.com (Jan Fure) wrote:

: I the code below, I am creating a data structure of array references.
: I want to loop through the keys, and for each key, which corresponds
: to multiple values, I want to dereference the data to get a plain
: array containing the values. I have read 'perlref', but it is still
: not clear to me.

Could you phrase that in the form of a question?  It's not clear what
you are misunderstanding.

: 	my %data;
: 	for $row ( @DATA2 ){ #@DATA2 is an array of arrays
: 		push @{ $data{$$row[0]} }, $$row[1];
: 	}
: 	my @points;
:   	foreach ( sort { $a <=> $b } keys %data ) {
:       	@{$data{$_}} = sort { $a <=> $b } @{$data{$_}};
                ^^^^^^^^^^^^                      ^^^^^^^^^^^^
$_ is a hash key.

$data{$_} is the hash value for that key.  That value is an array
reference.

@{ $data{$_} } is the referenced array.

Looks like you figured it out pretty well on your own.

:       	push @{$points[0]}, $_;
:       	push @{$points[1]}, $data{$_};
:   	}



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

Date: 25 Jun 2003 22:29:17 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Array dereferencing
Message-Id: <bdd7nt$s5c@dispatch.concentric.net>


"Jan Fure" <jan_may2002_fure@attbi.com> wrote in message
news:e47a84bf.0306251130.a70d5c9@posting.google.com...
> Hi;
>
> I the code below, I am creating a data structure of array references.
> I want to loop through the keys, and for each key, which corresponds
> to multiple values, I want to dereference the data to get a plain
> array containing the values. I have read 'perlref', but it is still
> not clear to me.
>
I think you're confusing two different aspects of dealing with data
structures.  If you are "creating a data structure of array references," you
are concerned with putting data *into* either an array of arrays or a hash
of arrays.  But if you "want to dereference the data to get a plain array"
you are concerned with getting data *out* of a pre-existing hash of arrays.
(Your use of the term "key" effectively narrows the choice of data
structures to a hash of arrays.)

How you get data *into* the hash of arrays depends on the data source.
Suppose that the data source is a file which you read line-by-line in a
while() loop and that the raw data looks like this:

    alpha gomez halter icicle
    beta halter jocular kingdom lambda
    gamma beta gomez lambda zebra

 ...where you can for arbitrary reasons assume that the first word in each
line can serve as a unique identifier for that line.  Then you can load up
your data structure like this:

    my (%data);
    while (<FILE>) {
        my @line = split;            # by default, split on whitespace
        $data{$line[0]} = [ @line ];
    }

To get data out of this structure, code like this:

   foreach (keys %data) {
       print "Key:  $_\tValues:  @{$data{$_}}\n";
   }

See if you can reduce your code to this level of simplicity.  My hunch is
that the example you took from the Cookbook is more elaborate than you
really need and that that is confusing you.  Also, get the code to do what
you want *without sorting the keys first*.  If you aren't clear on what
you're doing, throwing in the sort function will only confuse you more.
HTH.




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

Date: Wed, 25 Jun 2003 21:21:08 GMT
From: torsten.drees@t-online.de (Torsten Drees)
Subject: Re: ASN1.pm example required
Message-Id: <3efa10ec.2198983@news.t-online.de>

Hi Clyde,

Thanx for help. I am sorry for my late reply, but i already gave up my
hope to get help about asn1.pm. I fear it isn't used often. I will
find time next week to work on my asn.1 project. i will reply about
the results.


regards torsten  




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

Date: 25 Jun 2003 13:51:42 -0700
From: ambrice@yahoo.com (Aaron Brice)
Subject: Checking if a method is defined in perl 5.00503
Message-Id: <e6118b62.0306251251.6cb0fdc@posting.google.com>

I need to check that a method whose name is given in $methodName
exists.  In perl 5.8.0, "if (defined($myobj->$methodName))" seems to
work, but not in 5.00503, so I'm wondering what the 5.00503 equivalent
would be if it exists (upgrading is not an option right now).  The
following test code works in 5.8.0 but gives me a syntax error in
5.00503:

#!/usr/bin/perl
use strict;

my $myobj = new MyTest;
my $var = "testMethod";

if (defined($myobj->$var)) {
  my $ret = $myobj->$var();
  print "Defined: $ret\n";
} else {
  print "Not defined\n";
}

package MyTest;

sub new {
  my ($proto) = @_;

  my $self = {};
  bless($self, "MyTest");
  return $self;
}

sub testMethod {
  return 52;
}


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

Date: Wed, 25 Jun 2003 16:33:04 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Checking if a method is defined in perl 5.00503
Message-Id: <slrnbfk58g.5o0.tadmc@magna.augustmail.com>

Aaron Brice <ambrice@yahoo.com> wrote:

> I need to check that a method whose name is given in $methodName
> exists.  


   if ( $myobj->can($methodName) ) {
      print "object has a $methodName() method\n";
   }


See the docs for the universal class for more info:

   perldoc UNIVERSAL


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


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

Date: 25 Jun 2003 21:41:37 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: Checking if a method is defined in perl 5.00503
Message-Id: <3efa1711$0$204$75868355@news.frii.net>

Aaron Brice <ambrice@yahoo.com> wrote:
AB> I need to check that a method whose name is given in $methodName
AB> exists.  In perl 5.8.0, "if (defined($myobj->$methodName))" seems to
AB> work, but not in 5.00503, so I'm wondering what the 5.00503 equivalent
AB> would be if it exists (upgrading is not an option right now).  The
AB> following test code works in 5.8.0 but gives me a syntax error in
AB> 5.00503:

AB> #!/usr/bin/perl
AB> use strict;

AB> my $myobj = new MyTest;
AB> my $var = "testMethod";

AB> if (defined($myobj->$var)) {
AB>   my $ret = $myobj->$var();
AB>   print "Defined: $ret\n";
AB> } else {
AB>   print "Not defined\n";
AB> }

my $obj = new MyTest;
my $meth = "testMethod";

if ($obj->can($meth)) {
    print "Can: ", $obj->$meth(), "\n";
} else {
    print "Cannot\n";
}

AB> package MyTest;

AB> sub new {
AB>   my ($proto) = @_;
AB>   my $self = {};
AB>   bless($self, "MyTest");
AB>   return $self;
AB> }

AB> sub testMethod { 52 }

Regards,

Nicholas

-- 
"Why shouldn't I top-post?"    http://www.aglami.com/tpfaq.html
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

Date: 25 Jun 2003 23:59:24 GMT
From: ctcgag@hotmail.com
Subject: Re: Database Connection Pooling in Perl CGI Script WITHOUT mod_perl
Message-Id: <20030625195924.934$g5@newsreader.com>

pmbutler@attbi.com (Pete Butler) wrote:
> I'm working on a Perl CGI application, and I'd like to set up database
> connection pooling for obvious performance-related reasons.
>
> However, the server I'm working on is provided by a third party, so I
> do NOT have access to mod_perl.

That makes it tough.  You could have one long-lived non-CGI perl script
that held the connection and acted as agent to the CGI perl scripts, but
the overhead of connecting to that agent would be about as bad as the DB
connect in the first place.

>
> Does anybody know of a way I can do connection pooling under these
> conditions?  Or am I just screwed without mod_perl?
>
> (The database I'm accessing is MySQL, if that matters.)

Yes, it matters a lot.  Connecting to MySQL is so light weight that
there is little benefit to be had by pooling, IMHO.  Oracle is an entirely
different beast.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Wed, 25 Jun 2003 20:52:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <Pine.LNX.4.53.0306252033410.22782@lxplus072.cern.ch>

On Wed, Jun 25, Shambo inscribed on the eternal scroll:

[Oh dear, this _is_ getting to be more like some
hypothetical comp.encoding group...]

> We have a ton of text files from all over the world, often times
> including invalid UTF-8 characters such as ø or £

Well, your posting was encoded in iso-8859-1, so if that's to be
taken seriously, then you haven't got utf-8.  So what's the point of
trying to read it as utf-8?  It doesn't even remotely resemble it
(aside from the characters that are us-ascii anyway...).

> (that was an o with
> a line thru it, a la Scandanavian letters, and a British pound
> sterling symbol).

In iso-8859-1 (or Windows-1252, not that I'd encourage that), they
would indeed be.

> When I convert these text files to XML, the
> resulting XML is not valid becuase it contains these characters.

This is because you're not telling XML what your character coding is.

> I can
> map individual charatcers to their numerical equivalent (&#248; and
> &#163; in this case),

It's a valid choice.  But why the hell?  If you want to represent them
in utf-8, then do so.

In Perl 5.8 you just tell the input file handle that its encoding is
iso-8859-1, and the output file handle that its encoding is utf-8, and
the job is done.

In earlier Perls you'd use the Encode module explicitly...

> but I'm wary about performing such a conversion
> for each and every non UTF-8 valid sequence I may find.

Your mental model is way adrift, I'm afraid.  This talk of "non utf-8
valid sequences" strikes me as a bit like counting what you've been
told is a stack of pound notes and then being surprised that the stack
doesn't contain US dollars.

> So my question is, has someone found a way to automate converion of
> these charcters to their numerical equivalent without having to list
> every sinlge character?

Well yes, it's called an XML normaliser, and it's got nothing to do
with Perl.  You'd tell it that it was getting iso-8859-1 input, and
that you wanted us-ascii output, and that's what it would do.

But why would you want to do that, when XML likes to get utf-8 anyway?

You have the choice of either delivering utf-8 as XML likes it as
default, or telling XML that it's getting iso-8859-1.  Nothing to do
with Perl there, though.


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

Date: 25 Jun 2003 14:12:48 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Looking for inspiration: cascading CGI
Message-Id: <etok7b9rk5b.fsf@wormtongue.emschwar>

"codeWarrior" <GPatnude@HotMail.com> writes:
> I'd recomend #2 before I tried storing stuff in a logfile... you can pass
> form data pretty efficiently in hidden fields...

The only thing is, you need to be extra-careful about sanitizing the
input from those.  It only takes one person nasty enough to View
Source..., see how you're passing info that way, and try to do
something malicious with it.  Modules like LWP::Simple make it trivial
to spoof form submissions that way.

That's one reason people like using session data; you have a better
ability to control what gets stored and how.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Wed, 25 Jun 2003 18:42:57 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Oracle CLOB using DBI
Message-Id: <3EFA4191.3040903@comcast.net>

 From metalink Note 19792.1:

Error: ORA 3115

Text: unsupported network datatype or representation

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

Cause: A user bind or define, or an Oracle function, is not supported by 
this

heterogeneous SQL*Net connection.

Action: Upgrade the older version of Oracle and try again.

Do you have an old Oracle install on the machine the code is running on? 
  If so, this is your problem.

--
Ron Reidy
Oracle DBA

Ken Chesak wrote:
> Would you email my hotmail account again, I delete by mistake since
> 99% is junk mail.
> 
> I get the following error,
> 
> DBD::Oracle::db prepare failed: ORA-03115: unsupported network
> datatype or repre
> sentation (DBD: odescr failed) at clob.pl line 26.
> 
> It runs if I use dbms_lob.substr( comments, 30000, 1).
> 
> $dbh->{LongReadLen} = 512 * 1024 ;
> $dbh->{LongTruncOk} = 1;
> 
>         $sth1 = $dbh->prepare(q{
>                SELECT cd_type, comments
>                FROM comments WHERE id_comment = 53
>        });
> 
>        $sth1->execute();
> 
>         while ( ($name, $data) = $sth1->fetchrow_array ) {
> 
>                 print "row = $name $data \n";
> 
>         }


-- 
Ron Reidy
Oracle DBA



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

Date: Wed, 25 Jun 2003 19:50:59 GMT
From: Ed Murray <ed.murray@attbi.com>
Subject: Re: Perl & HTTP
Message-Id: <6rjekbm09yex.16icvtzgdpi93$.dlg@40tude.net>

Thanks Folks !!!
Ed


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

Date: 25 Jun 2003 14:11:53 -0700
From: oefinger@mit.edu (Matt Oefinger)
Subject: perl memory management - does @array = () free the memory?
Message-Id: <e9b08c9f.0306251311.10928437@posting.google.com>

I have a sizable array that I want to clear (i.e. free the memory for
other use).
Will @array = () alert a garbage collector in Perl to mark the memory
as unallocated or do I need to perform this tast manually?

Thanks
Matt


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

Date: 25 Jun 2003 21:44:19 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: perl memory management - does @array = () free the memory?
Message-Id: <3efa17b3$0$204$75868355@news.frii.net>

Matt Oefinger <oefinger@mit.edu> wrote:
MO> I have a sizable array that I want to clear (i.e. free the memory for
MO> other use).
MO> Will @array = () alert a garbage collector in Perl to mark the memory
MO> as unallocated or do I need to perform this tast manually?

Did you read:

	$ perldoc -q free

Regards,

Nicholas

-- 
"Why shouldn't I top-post?"    http://www.aglami.com/tpfaq.html
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

Date: 25 Jun 2003 16:51:23 -0700
From: dzchoi@hotmail.com (Dozy Choi)
Subject: Re: problem of backslash conversion with MKS perl
Message-Id: <3ce23aec.0306251551.ca14781@posting.google.com>

> What is "MKS Perl"?  What is your platform?  OS?  I have an idea your 
> command shell is doing exactly what is supposed to do, and that you for 
> some reason think it should do something else.  Perhaps you should write 
> your own shell which will do things your way?  I don't think your 
> question has anything to do with Perl specifically -- a program written 
> in any other language would receive the same arguments from your shell, 
> would it not?  Hint: Try it and see.

Ah... I am sorry. I am running the MKS perl on windows 2000. And MKS
perl is a kind of variation(?) of Perl5.8.0 compiled by MKS
corp.(http://www.mks.com)

> I note that the Perl and OS I am using at the moment (Perl v5.8.0 
> ActiveState build 805 on Windoze 98SE with the command.com "shell") does 
> not have the behavior you describe.  It passes alphanumeric arguments 
> containing / and \ literally, character for character.  Example:
> 
>      D:\junk>type junk326.pl
>      use Data::Dumper;
>      print Dumper(@ARGV);
> 
>      D:\junk>perl junk326.pl a/b\c//d\\e
>      $VAR1 = 'a/b\\c//d\\\\e';

But it is still not working:
C:\USR>perl junk.pl a/b\c//d\\e
$VAR1 = 'a/b/c//d//e';


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

Date: Wed, 25 Jun 2003 16:57:50 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Quick Q about $|
Message-Id: <Xns93A5B6AAFE045sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Matthew Weier O'Phinney <matthew@weierophinney.net> wrote in
news:_NiKa.111694$zm1.98342@twister.nyroc.rr.com: 

> * Raj <rajkothary@hotmail.com>:
>> What does:
>> 
>>      $|=1; select(STDOUT);
>> 
>> do?  I understand that STDOUT is selected as the default handle, but
>> what about the bit preceding it?
> 
> $! = output autoflush. STDOUT is typically line buffered, which means
> that there will often be a delay in seeing output if you're piping to
> another process (CGI and rsh are two examples). By setting $| to a
> non-zero value, you 'turn off' the buffering (actually, it flushes
> using fflush(3) after each command that should be piped to STDOUT,
> usually print or write).

Not STDOUT, but rather whatever filehandle was selected at the time $| was 
set.  The OP's example is sorta backward.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPvoaw2PeouIeTNHoEQJJBgCfeHXVj37NOyQVqOyK+MsuAtMY5qIAnA43
ta3Xmw0O8TBCxtYAsFaPi9sj
=ABLm
-----END PGP SIGNATURE-----


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

Date: Wed, 25 Jun 2003 11:53:37 -0700
From: "Jim McTiernan" <james.mctiernan@rcn.com>
Subject: Re: search for messages in large files
Message-Id: <bdcr7t$p8h$1@bob.news.rcn.net>


"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrnbfi35g.1ip.mgjv@verbruggen.comdyn.com.au...
> On Tue, 24 Jun 2003 19:27:20 -0700,
> Jman <james.mctiernan@rcn.com> wrote:
> > I am working with files that grow to a size of 1-2 mb each day
> > of the month.  The file is closed at the end of each month.
> > The format of the messages is:
> >
snip
>
> It would be better to include _real_ data from your log file, and even
> better to show more than one record, so we can see whether there is
> anything between records/messages that can be used.
>
> > I want to do a search of the files each day for some previous days
messages.
> > The important data in the message to me is the date (YY-MN-DY),
> > and the MSG1 (actually MSG[1-50]).  Some of the messages have data
> > in every  line (MSG1), and some messages have lines that are blank
followed
> > by lines with data.  Is there a good, or simple way to gather into a new
> > file
> > all of the previous days MSGs that I want?  Hope my question makes
sense.
>
> Maybe something like (untested):
>
> my $yesterday = "03-06-25"; # assuming that that is the format
> open F, "mylogfile" or die $!;
> while (<F>)
> {
>     if (/$yesterday.*MSG(\d\d?)/)
>     {
> # We now have the message number in $1
> # Since you're only interested in yesterday, you already know
> # the date. No need to capture it.
> print;
>     }
> }
> close F;
>
> I am assuming that none of the other lines have that pattern. I'm also
> assuming that the BBBB bits above don't contain anything matching
> 'MSG\d\d?', or if it foes that it's actually the correct number as
> well.
>
> Hard to tell whether this is sufficient. You give us very little
> information about what exactly you're having trouble with. next time,
> apart from showing real data, also show us what you have tried (real
> code), and which bit exactly you're having trouble with.
>
> Martien
> --
>                         |
> Martien Verbruggen      | True seekers can always find something to
> Trading Post Australia  | believe in.
>                         |

Below is an example of the data that I was trying to reflect.
There is a CTRL M at end of each line after the line that starts "-----New".
and there is a CTRL Y on the line prior to the line that starts "-----New".
I am new at this obviously, my original approach was to delete the data that
I don't need to try to group the messages into paragraphs:
#!/usr/bin/perl -w
while (<>) {
   s/^M|^Y|^-.*//;
   print:
}

Then I pipe that to another program:
#!/usr/bin/perl -w
$/ = "";
while (<>) {
   print if / 03-06-01 /;
}

Here is some file data:

-----New Message Received on 06-01-2003 at 00:00:03 -----

   S21D-685375656 03-06-01 00:00:03 611259 TIME SANF
   REPT TIME 03-06-01 00:00:03

-----New Message Received on 06-01-2003 at 00:00:06 -----

   S570-58785830 03-06-01 00:00:06 611262 SLC SANF
*  REPT RT SID=2050 DNUSRT=2-0-60 MINOR FAR END EVENT=12489

-----New Message Received on 06-01-2003 at 02:47:03 -----

   S570-58785830 03-06-01 02:47:03 612603 MDIIMON SANF
A  REPT MDII CVN  SIGTYPE ISUP    TKGMN 303-4  SZ 168  OOS 0 ID
     SUPRVSN   TIME 02:47:03    NEN=2-0-0-1-1-4-3-4 TRIAL 1 CARRFLAG NC
     OGT  NORMAL  CALL  CALLED-NO 1288  CALLING-NO 9033
     DISCARD 0
     OPC   123083056  DPC  456041003  CIC  3004

-----New Message Received on 06-01-2003 at 02:53:01 -----

   S32C-942407807 03-06-01 02:53:01 612617 MAINT SANF
M  REPT AUDSTAT COMPLETED

     ROUTINE AUDIT SCHEDULING IS ALLOWED

-----New Message Received on 06-01-2003 at 02:54:01 -----

   S570-58785830 03-06-01 02:54:01 612619 TRCE SANF
A  TRC IPCT EVENT 2621

     DN=9759 TERM=3-H'329f DIALED


     DN=5551212
     TIME 02:54:01





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

Date: 25 Jun 2003 23:41:42 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: search for messages in large files
Message-Id: <slrnbfkcpn.1hq.mgjv@verbruggen.comdyn.com.au>

On Wed, 25 Jun 2003 11:53:37 -0700,
	Jim McTiernan <james.mctiernan@rcn.com> wrote:
> 
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrnbfi35g.1ip.mgjv@verbruggen.comdyn.com.au...
>> On Tue, 24 Jun 2003 19:27:20 -0700,
>> Jman <james.mctiernan@rcn.com> wrote:
>> > I am working with files that grow to a size of 1-2 mb each day
>> > of the month.  The file is closed at the end of each month.
>> > The format of the messages is:
>> >
> snip
>>
>> It would be better to include _real_ data from your log file, and even
>> better to show more than one record, so we can see whether there is
>> anything between records/messages that can be used.
>>
>> > I want to do a search of the files each day for some previous days
> messages.
>> > The important data in the message to me is the date (YY-MN-DY),
>> > and the MSG1 (actually MSG[1-50]).  Some of the messages have data
>> > in every  line (MSG1), and some messages have lines that are blank
> followed
>> > by lines with data.  Is there a good, or simple way to gather into a new
>> > file
>> > all of the previous days MSGs that I want?  Hope my question makes
> sense.
>>
>> Maybe something like (untested):
>>
>> my $yesterday = "03-06-25"; # assuming that that is the format
>> open F, "mylogfile" or die $!;
>> while (<F>)
>> {
>>     if (/$yesterday.*MSG(\d\d?)/)
>>     {
>> # We now have the message number in $1
>> # Since you're only interested in yesterday, you already know
>> # the date. No need to capture it.
>> print;
>>     }
>> }
>> close F;
>>
>> I am assuming that none of the other lines have that pattern. I'm also
>> assuming that the BBBB bits above don't contain anything matching
>> 'MSG\d\d?', or if it foes that it's actually the correct number as
>> well.
>>
>> Hard to tell whether this is sufficient. You give us very little
>> information about what exactly you're having trouble with. next time,
>> apart from showing real data, also show us what you have tried (real
>> code), and which bit exactly you're having trouble with.
> 
> Below is an example of the data that I was trying to reflect.
> There is a CTRL M at end of each line after the line that starts "-----New".
> and there is a CTRL Y on the line prior to the line that starts "-----New".
> I am new at this obviously, my original approach was to delete the data that
> I don't need to try to group the messages into paragraphs:
> #!/usr/bin/perl -w
> while (<>) {
>    s/^M|^Y|^-.*//;
>    print:
> }

So... You're removing any initial M or Y, or anything in a line that
initially starts with -?

> Then I pipe that to another program:
> #!/usr/bin/perl -w
> $/ = "";
> while (<>) {
>    print if / 03-06-01 /;
> }

And now you print "paragraphs" that contain that date.

> Here is some file data:
> 
> -----New Message Received on 06-01-2003 at 00:00:03 -----
> 
>    S21D-685375656 03-06-01 00:00:03 611259 TIME SANF
>    REPT TIME 03-06-01 00:00:03
> 

Well.. That data doesn't look at all like what you described in your
original post. In your OP, you were talking about being interested in
some message number, and the date only. I don't see any message
number.

Given that ctrl-Y seems to be the record separator, or terminator, I'd
probably set $/ to ctrl-Y, and then process the file message by
message, selecting on whichever criteria you want, and I'm more
confused now about what you do and don't want. I'll just make up
something, and leave it up to you to change it. You're not clear on
whether all of the dates in those messages can be used, or whether it
has to be one in the capitalised bits. I'll simply select on that
first line, because it's easier.


#!/usr/local/bin/perl 
use strict;
use warnings;

# Set record separator to ctrl-Y followed by a newline
$/ = "\cY\n";
my $target_date = "06-01-2003";

while (<DATA>)
{
    chomp;

    # We're only interested in records that contain our target date
    next unless /Received on $target_date at/;

    # Remove any M or Y following a newline (Just following your code,
    # I think)
    s/\n(M|Y)/\n/g;

    # Remove that first line. We are not interested in it.
    s/\A.*--\n//;

    # Print what's left
    print;
}

__DATA__
-----New Message Received on 06-01-2003 at 00:00:03 -----

   S21D-685375656 03-06-01 00:00:03 611259 TIME SANF
   REPT TIME 03-06-01 00:00:03

-----New Message Received on 06-01-2003 at 00:00:06 -----

   S570-58785830 03-06-01 00:00:06 611262 SLC SANF
*  REPT RT SID=2050 DNUSRT=2-0-60 MINOR FAR END EVENT=12489

-----New Message Received on 06-01-2003 at 02:47:03 -----

   S570-58785830 03-06-01 02:47:03 612603 MDIIMON SANF
A  REPT MDII CVN  SIGTYPE ISUP    TKGMN 303-4  SZ 168  OOS 0 ID
     SUPRVSN   TIME 02:47:03    NEN=2-0-0-1-1-4-3-4 TRIAL 1 CARRFLAG NC
     OGT  NORMAL  CALL  CALLED-NO 1288  CALLING-NO 9033
     DISCARD 0
     OPC   123083056  DPC  456041003  CIC  3004

-----New Message Received on 06-01-2003 at 02:53:01 -----

   S32C-942407807 03-06-01 02:53:01 612617 MAINT SANF
M  REPT AUDSTAT COMPLETED

     ROUTINE AUDIT SCHEDULING IS ALLOWED

-----New Message Received on 06-01-2003 at 02:54:01 -----

   S570-58785830 03-06-01 02:54:01 612619 TRCE SANF
A  TRC IPCT EVENT 2621

     DN=9759 TERM=3-H'329f DIALED


     DN=5551212
     TIME 02:54:01


Martien
-- 
                        | 
Martien Verbruggen      | Useful Statistic: 75% of the people make up
Trading Post Australia  | 3/4 of the population.
                        | 


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

Date: Wed, 25 Jun 2003 17:14:17 -0500
From: Buteo Lagopus <lbl@pbzpnfg.arg>
Subject: system("clear"); vs. system("cls");
Message-Id: <Xns93A5B9537156Ayoycomcastnet@206.127.4.25>

Using ActiveState Perl 5.8.0, system("clear"); raises an error on Win2k 
Pro: "clear is not recognized as an internal or external command, operable 
program or batch file." but that's what perldoc says to use.

I tried system("cls"); and it worked correctly.

Is perldoc in error or is this an OS port issue? I'd hope this won't cause 
cross-platform problems.

Any thoughts?

Thanks,

Andy


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

Date: Wed, 25 Jun 2003 15:28:57 -0700
From: Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us>
Subject: Re: system("clear"); vs. system("cls");
Message-Id: <9n7ddb.6q6.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In article <Xns93A5B9537156Ayoycomcastnet@206.127.4.25>, Buteo Lagopus wrote:
> Using ActiveState Perl 5.8.0, system("clear"); raises an error on Win2k 
> Pro: "clear is not recognized as an internal or external command, operable 
> program or batch file." but that's what perldoc says to use.

perldoc -f system

which will refer you to

perldoc -f exec

the first line of which may be illuminating.

> Is perldoc in error or is this an OS port issue? I'd hope this won't cause 
> cross-platform problems.

Using system() is one of the easier ways to cause cross-platform
problems, especially across unix-like and Win32-like systems.

- --keith

- -- 
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
alt.os.linux.slackware FAQ:  http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj76IicACgkQhVcNCxZ5ID8NzwCgmgp6KoKCOubYaRWjTmwztbSc
zfUAoI3Cr9O7Cq1yW/KFAmLte7wtb50E
=MV3d
-----END PGP SIGNATURE-----


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

Date: Wed, 25 Jun 2003 17:36:54 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: system("clear"); vs. system("cls");
Message-Id: <slrnbfk906.5u4.tadmc@magna.augustmail.com>

Buteo Lagopus <lbl@pbzpnfg.arg> wrote:

> Using ActiveState Perl 5.8.0, system("clear"); raises an error on Win2k 
> Pro: "clear is not recognized as an internal or external command, operable 
> program or batch file." but that's what perldoc says to use.


Because that is what you should use on unix.


> I tried system("cls"); and it worked correctly.


Because that is what you should use on windows.


> Is perldoc in error or is this an OS port issue? 


It is an OS port issue.


> I'd hope this won't cause 
> cross-platform problems.


It most certainly will cause cross-platform problems, the same
as system('ls') vs. system('dir')...

How to clear a display is going to depend a great deal on which
display it is that is doing the displaying.  :-)


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


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

Date: Wed, 25 Jun 2003 18:38:24 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Using Formats and stopping between pages
Message-Id: <3EFA4080.8090706@comcast.net>

There is a Pager module described in Object Oriented Perl by Damian 
Conway that might do this for you.

--
Ron Reidy
Oracle DBA

Crixx wrote:
> Hello,
> 
> I am writing a menu-line program. For presenting some data I use a
> regular format and a Top-of-page format.
> 
> Inside a while loop I call the format. The paging is done fine it puts
> the top-of-page heading fine, page number and so on, but the whole
> result scrolls through the screen. I would like it to pause beteen
> page and page, so that the user can read it.
> 
> Is there a way to do it?
> 
> Please help me I have been looking through all FAQ and newsgroups.
> 
> TIA and regards,
> Cristina
> 
> Some of my code is:
> 
> format WEB_SERVICES =
> @<: @<<<<<<<<<<<<<<<<<  with URL: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> $line_number, $web_data[6], $web_data[11]
>                         Instance:@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> $web_data[0]
> ----------------------------------------------------------------------
> .
> 
> while ($line = <CONFIG>) {
> 		@web_data = split(/\|/,$line);
> 		write;
> 		$line_number ++;
> 	}


-- 
Ron Reidy
Oracle DBA



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

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.  

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 5136
***************************************


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