[22917] in Perl-Users-Digest
Perl-Users Digest, Issue: 5137 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 26 03:05:50 2003
Date: Thu, 26 Jun 2003 00:05:11 -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 Thu, 26 Jun 2003 Volume: 10 Number: 5137
Today's topics:
Re: Accessing constants from another package/file. <mgjv@tradingpost.com.au>
Re: Checking if a method is defined in perl 5.00503 <mgjv@tradingpost.com.au>
Hide source, compiling, whatever! (Mike)
Module of sending http 1.1 and/or 1.0 requests (Yuchung Cheng)
Re: Module of sending http 1.1 and/or 1.0 requests <bdonlan@bd-home-comp.no-ip.org>
Re: Module of sending http 1.1 and/or 1.0 requests <abigail@abigail.nl>
Offer tips, comments on this code (generates html to in <spamblock@junkmail.com>
Re: Perl -e `"dir a*.txt"` (James Willmore)
Perl 5.6 and Perl 5.8 <alvise@hochfeiler.it>
Perl Forking Server Problems (Jeff Chinnock)
problem when use debug perl in win2000 os <heye@v2tech.com>
problem when use debug perl in win2000 os <heye@v2tech.com>
Re: search for messages in large files <james.mctiernan@rcn.com>
Re: search for messages in large files (Sam Holden)
Re: search for messages in large files <mgjv@tradingpost.com.au>
Re: system("clear"); vs. system("cls"); <tim@vegeta.ath.cx>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jun 2003 01:24:08 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Accessing constants from another package/file.
Message-Id: <slrnbfkipq.1hq.mgjv@verbruggen.comdyn.com.au>
On 25 Jun 2003 08:37:35 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote in comp.lang.perl.misc:
>> Hey all. I'm trying to use some constants that I have defined
>> using the "constant" module. I'm requiring the file into another
>> package. The package that uses the constant is used from "main".
>>
>> The problem is that it isn't getting the value of the constant,
>> it's just using the string value of the constant name. Uh, don't
>> know if that made sense.
>
> [...]
>
>> Here's the relevant code:
>>
>> #start myScript.pl
>> { package LineFixer;
>>
>> require 'ErrorManager.pl';
>> require 'DE_Constants.pl';
>
> Change 'require' to 'use' here. Also, switch on strictures and warnings.
> With those Perl would have pointed out the problem.
If you do that, you'll also have to change the pl files into modules
(and they have to have the extension pm). You also need to take into
account that import wil be called on the module. I agree that for
moderm code this is the best action to take.
If the files are just perl "libraries" in the old sense (a bunch of
subroutines packed together in a file), require is the correct way to
include them. If you ened them included at compile time, put it in a
BEGIN block.
OP: Have a read of the entry for C<use> in the perlfunc documentation,
as well as the entry for C<require>, which you presumably already
read.
I have no quibbles with the advice to siwtch on strictures and
warnings.
Martien
--
|
Martien Verbruggen | True seekers can always find something to
Trading Post Australia | believe in.
|
------------------------------
Date: 26 Jun 2003 01:17:14 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Checking if a method is defined in perl 5.00503
Message-Id: <slrnbfkics.1hq.mgjv@verbruggen.comdyn.com.au>
On 25 Jun 2003 13:51:42 -0700,
Aaron Brice <ambrice@yahoo.com> wrote:
> 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
That will only give the right answer if $methodName returns a defined
value. It will also actually be executed, and if that has side
effects, you might not want to do that. Besides that, It'll throw a
fatal error if $methodName doesn't exist, even in 5.8.0, so I'm not
sure how you can say that it works.. you'd need an eval{} around it.
> 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:
In 5.8.0 $object->$varname is interpreted as a call to method $varname
on $object. In 5.00503 you need to make that more clear by adding some
parentheses: $object->$varname(); That should also make clear that it
is not what you think it is.
Observe what the following does (and note that it doesn't compile on
Perls before 5.6.0 for the abovestated reason):
#!/usr/local/bin/perl
use strict;
use warnings;
package Grub;
sub new { bless {}, $_[0] }
sub false { print "false called\n"; undef }
sub true { print "true called\n" ; 1 }
package main;
my $grub = Grub->new;
my $method = "grub";
print "grub defined\n" if eval { defined $grub->$method };
print "grub can()\n" if defined $grub->can($method);
$method = "false";
print "false defined\n" if defined $grub->$method;
print "false can()\n" if defined $grub->can($method);
$method = "true";
print "true defined\n" if defined $grub->$method;
print "true can()\n" if defined $grub->can($method);
Martien
--
|
Martien Verbruggen | +++ Out of Cheese Error +++ Reinstall
Trading Post Australia | Universe and Reboot +++
|
------------------------------
Date: 25 Jun 2003 21:19:36 -0700
From: csdude@hotmail.com (Mike)
Subject: Hide source, compiling, whatever!
Message-Id: <46cdc619.0306252019.1d4e588f@posting.google.com>
Hey, I have several programs that I would like to install on a
client's website. However, this client has been known to be very good
friends with a local competing designer (who happens to be a terrible
programmer), and in my opinion is very likely to give his friend
access to the server and download my programs, regardless of
copyright. One of these programs I've spent years perfecting, and I
would be pretty upset if it was swiped by this guy.
So, I've been researching ways of keeping this from happening. Some of
the programs will call certain modules, some of which come with Perl
and others are installed manually. I program on a Windows 98 machine
(and test with ActivePerl 5.8.0 and Apache 1.3.27), but upload to a
Linux Redhat 6.2 server running Apache 1.3.26.
At this point, I am looking for any option possible. I tried Perl2Exe,
but can't get even the simplest script to work in the browser (they'll
work at the Dos command prompt, but not when I try to open them from
the browser). I've also tried PerlCC that came with ActivePerl, but
get nothing but errors when trying to compile (and it never completes
the compilation).
Are there any modules that I can install to permanently encrypt the
source code? Any other suggestions? This would likely be a one-time
occurrence, so I'm hesitant to buy a program unless I have to, but at
this point I'm open to any suggestions.
TIA,
Mike
------------------------------
Date: 25 Jun 2003 18:25:24 -0700
From: yuchung@mail.com (Yuchung Cheng)
Subject: Module of sending http 1.1 and/or 1.0 requests
Message-Id: <c5a86edd.0306251725.14dd1c55@posting.google.com>
Anybody knows what perl module I can use to specify the http request as
http 1.1 or 1.0? It seems I can't do that with http::request. Thank you.
Yu-chung
------------------------------
Date: Wed, 25 Jun 2003 21:27:16 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Module of sending http 1.1 and/or 1.0 requests
Message-Id: <pan.2003.06.26.01.27.16.347494@bd-home-comp.no-ip.org>
On Wed, 25 Jun 2003 18:25:24 -0700, Yuchung Cheng wrote:
> Anybody knows what perl module I can use to specify the http request as
> http 1.1 or 1.0? It seems I can't do that with http::request. Thank you.
Have you taken a look at LWP?
------------------------------
Date: 26 Jun 2003 01:54:45 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Module of sending http 1.1 and/or 1.0 requests
Message-Id: <slrnbfkkj5.el.abigail@alexandra.abigail.nl>
bd (bdonlan@bd-home-comp.no-ip.org) wrote on MMMDLXXXVI September
MCMXCIII in <URL:news:pan.2003.06.26.01.27.16.347494@bd-home-comp.no-ip.org>:
%% On Wed, 25 Jun 2003 18:25:24 -0700, Yuchung Cheng wrote:
%%
%% > Anybody knows what perl module I can use to specify the http request as
%% > http 1.1 or 1.0? It seems I can't do that with http::request. Thank you.
%%
%% Have you taken a look at LWP?
Considering that HTTP::Request is part of the LWP bundle, what do you
think the answer to your question is?
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
Date: Wed, 25 Jun 2003 23:35:55 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Offer tips, comments on this code (generates html to index image files)
Message-Id: <vfl59v90q9j6d9@corp.supernews.com>
Please offer suggestions, comments, and tips on the following perl code. I
had a need to quickly generate an html document indexing and displaying all
image files within a given directory.
To use:
Save the script to somewhere within your $path. CD into any directory
containing a series of image files. execute the script (no command line
parameters). It scans the directory, and outputs an html document with img
src tags for each image, and a href tags for links to each image. If you
click on one of the links (from the html document), the image will be
displayed by itself in a separate popup window on a web browser.
This was my first perl project. Necessity is the mother of invention. I
"overwrote" it to make it easy to modify in the future. I'd like to hear
comments:
---------------------------------------
#!/usr/bin/perl
# imgdir2html.pl v1.02 (c)David Oswald
# Send comments to davido@pacifier.com
# The purpose of this little script is to parse a single directory, reading
in all
# files named *.jpg, *.tif, *.jpeg, *.tiff, *.bmp, and *.gif, and outputting
an HTML
# page to index those files. Links will create popup windows for the
individual images.
# The output html file will list the images in alphabetical order,
# given Perl's notion of alphabetical.
# Known limitations:
# Command line arguments are ignored for now. Sorry.
# Only works on current directory unless $dirname is modified prior to
runtime.
# Entire directory is read in at once and manipulated as an array. It's
possible
# that if the directory is truly massive, the array will overgrow memory
constraints.
# However, for this to happen, this little program is the least of your
worries; HELLO, try
# organizing your directory structure a little!
# The easiest way to customize this application is to modify the
declarations.
# --- Declarations ---
my ($outfile)="index.html"; # declare the output html file's name.
my (@imagefiles); # declare the list to hold the image files. Leave undef
until list retrieved.
my ($dirname) = "./"; # define the input directory.
my ($htmltitle)="Picture List"; # Give a title to the output html document
via <title> tag,
# and a first line <h1> caption.
# --- Main body ---
if (@imagefiles = getdir($dirname)) { #get list of image files or exit if
none found.
openhtmlfile($outfile); #open the output html file.
printheader($htmltitle); #print the html header.
printlinks(@imagefiles); #print the body links.
printfooter(); #print the terminating tags to the html file.
closehtmlfile(); #close the html output file.
} else {
print "Exiting: Current directory is empty.\n";
}
# --- End main body ---
# --- Subroutine definitions ---
sub getdir() { #Opens the current directory and gets all image filenames
into an array.
my ($dir)=@_;
my @entries;
opendir (CURRENTDIR, $dir) || die "Error: Unable to open directory: $dir \n
$!";
while (defined ( $file = readdir(CURRENTDIR))) {
if ($file =~ /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i) {
push (@entries,$file);
}
}
closedir(CURRENTDIR);
return sort(@entries);
}
sub openhtmlfile() { #Opens (@_) as file HTML for output.
my ($filename)=@_; #name the file to be opened using the input parameter.
if (-e $filename) { #Check. If file already exist prompt to overwrite or
exit.
print "Warning: $filename already exists. Overwrite? (y/n) ";
unless (<STDIN> =~ /^y/i) {
exit;
}
}
open (HTML, ">$filename") || die "Error: Unable to open $filename for
output.\n $!";
return;
}
sub printheader() { #Prints the html header to the outfile.
my ($title)=@_; #$title becomes both the html title as well as the <h1>
header.
print HTML "<html>\n<head>\n<title>$title</title>\n</head>\n";
print HTML "<body>\n";
print HTML "<h1>$title</h1>\n";
print HTML "<hr>\n<p>\n";
print HTML "Click on any link to open image in its own window. \n";
print HTML "By opening an image in its own window, you can print or easily
save ";
print HTML "individual images.\n";
print HTML "</p><hr>";
return;
}
sub printlinks() { #Prints an img src and href tag for each image in the
current dir.
my @filelist = @_;
foreach (@filelist) {
print HTML "<p>\n<img src=$_ alt=$_>\n<a href=\"$_\"
target=\"ImageWindow\"><br>$_</a>\n</p>\n";
}
return;
}
sub printfooter() { #Prints an html footer; the "closing" stuff.
print HTML "</body>\n</html>\n";
return;
}
sub closehtmlfile() { #Closes the html outfile.
close(HTML) || die "Error: Unable to close $filename after output.\n $!";
return;
}
--------------------------------------------
--
DJO
------------------------------
Date: 25 Jun 2003 22:56:37 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Perl -e `"dir a*.txt"`
Message-Id: <e0160815.0306252156.66b8f491@posting.google.com>
>
> Perl -e `"dir a*.bat"`
maybe you meant:
perl -e 'system("dir a*.bat")'
'dir' is a system command, so you should use the system function. You
MAY have to change the quoting to work on a WIN32 system.
HTH
Jim
------------------------------
Date: Thu, 26 Jun 2003 08:25:18 +0200
From: Alvise Valsecchi <alvise@hochfeiler.it>
Subject: Perl 5.6 and Perl 5.8
Message-Id: <3EFA91CE.19926486@hochfeiler.it>
Hi, I am new to this newsgroup, hence you might have discussed this
topic in the past. Sorry for this.
Here stands my problem: I wrote a network daemon that has been working
fine under Perl 5.6 and Red Hat 7.3 for many months.
Then I installed Red Hat 8, and Perl 5.8 that comes togheter, and the
script started failing continuously.
I investigated and discovered that Perl 5.8 introduces Unicode as a
default, but there should be more than this.
I solved the problem continuing running RedHat 7.3 and Perl 5.6, but I
don't want to surrender because soon or later I should install some more
recent RedHat release.
These are my questions: is Perl 5.8 backward compatible ? If not, how
can I trace *all* the differences ? Is it possible that the Perl porters
permitted RedHat to distribute a bugged Perl release ? How can I stay
up-to-date with potential Perl problems ?
TIA. Alvise.
------------------------------
Date: 25 Jun 2003 18:28:14 -0700
From: littleretsam@yahoo.com (Jeff Chinnock)
Subject: Perl Forking Server Problems
Message-Id: <49fcf7a7.0306251728.1a1a4160@posting.google.com>
Hello!
Perl newbie having a problem with a forking perl server that needs to
receive information from a socket, format it, and send it on to
another local socket. At this point, I am unable to determine where
the problem exists and have gone through many iterations and am unable
to determine why it 1) seems to hammer the CPU - i don't think this
should be happening, but I'm not sure where the true problem is 2)
believe that there is a problem with the interaction between parent
and child with the $connection variable, but again, don't know why.
Any insight into my problem would be greatly appreciated.
Jeff
#!/usr/bin/perl -w
#
#
# AUTHOR: Jeff Chinnock - contrib: Jacque Bussey, Joe Burton, Mike
Winter
# NAME: nco_logreader.pl
# CREATE DATE: 2003.3.1
# ABSTRACT: Probe for taking data from a logfile and sending to
multiple socketprobes
#
# USAGE: nco_logreader -config <Config File Path & Name>
#
# REVISION HISTORY:
##############################
## Define Modules and Options
use strict;
use POSIX qw(:sys_wait_h);
use IO::File;
use IO::Socket;
##############################
## Define Variables and Arrays
my $config = "/tmp/EACO.conf"; ## Default location for configfile.
User must enter other value on command line
my $debug = 0; ## 0 = NONE, 1 = DEBUG - Change in configfile
my $delimiter = "\;"; ## Default delimiter for records. Change in
configfile
my $rulesheader = "DCO_RAW_FEED"; ## Default header for all records.
MUST change in configfile.
my ($debugfile,$headerlength,$recordlength);
my ($listenSocket,$n,$serverIP,$serverPort) = '';
my ($spSock,$name,$spHost,$spPort) = '';
# Take input from the command line if necessary
while (@ARGV) {
$config = $ARGV[1] if ($ARGV[0] =~ /-config/);
help_menu() if($ARGV[0] =~ /-help/);
shift;
}
# Read configuration file - please ask Jeff Chinnock if you want to
change this file
read_configfile($config);
$listenSocket = IO::Socket::INET-> new (LocalPort => $serverPort,
LocalAddr => $serverIP,
Listen => 2000,
Proto => 'tcp',
Reuse => 1,
);
fatal_error("Cant create a listening socket: $@") unless
$listenSocket;
log_message("INFO: Listening socket ready on $serverIP:$serverPort")
if($debug);
$spSock = IO::Socket::INET-> new (PeerPort => $spPort,
PeerAddr => $spHost,
Proto => 'tcp',
);
fatal_error("Cant create a connection to socket probe socket: $@")
unless $spSock;
log_message("INFO: Socket probe socket ready on $spHost:$spPort")
if($debug);
$SIG{CHLD} = \&reaper;
#$SIG{CHLD} = 'IGNORE';
while(1) {
# Accept child connection
next unless my $connection = $listenSocket->accept;
# Set up $data and $origdata variables for use in substr
my ($data,$origdata);
defined (my $child = fork()) or fatal_error("Can't fork child:
$!");
# If I am a child process, work on data coming in
if ($child == 0) {
# my ($count,@events,$header); MOVED BELOW FOR SECTION WHERE NEEDED
print $connection "OK\n";
# Close child copy of listen socket, we will not take any more data
here
$listenSocket->close;
# Take incoming information and put into variables $data and
$origdata for processing
while (<$connection>) {
$data = $_;
$origdata = $_;
if ($data) { last; }
}
my ($count,@events,$header);
for($count=0; $data; $count++) {
if ($count == 0) {
# If i am first piece of data, take out length of header based on
value from configfile
$header = substr($data,0,$headerlength,''); }
else {
# In the meat of the processing section, parse each piece of data
into a unique record
$events[$count-1] = substr($data,0,$recordlength,'');
# We have moved the following line from below to here so it doesn't
have to reprocess the event again
print $spSock "$rulesheader$delimiter$header$delimiter$events[$count-1]\n";
}
}
exit 0;
}
# Close connection to mainframe process
$connection->close;
}
##############################
### Define subroutines
sub log_message {
####### WARNING, THIS SUBROUTINE ACCESSES A GLOBAL VARIABLE
# This sub takes a message and dumps it to the log file.
my $message = $_[0]; # Message to send to the logfile
$message =~ s/\n//; # Remove Newlines, keep log tidy
# Open log file
sysopen(LOG,$debugfile,O_WRONLY|O_APPEND|O_CREAT) or die("Unable
to open log file: $debugfile: $!");
# Send the message to the log, prepend a timestamp.
print LOG scalar(localtime) .": $message\n";
close(LOG);
# Roll logfile over when greater than 100000 bytes
if (-s $debugfile > 100000) {
rename($debugfile,"$debugfile\_old") or fatal_error("ERROR:
Unable to rename $debugfile to $debugfile\_old.");
log_message("INFO: $debugfile has grown larger than 100000
bytes, and has been backed up.") if($debug);
}
}
sub fatal_error {
my $error = $_[0]; # Passed in error.
log_message("ERROR: $error") if($debug); # Send the message to the
log
print STDERR $error; # Display the error to stderr
exit(1); # Exit script
}
sub reaper {
1 until (-1 == waitpid(-1,WNOHANG));
$SIG{CHLD} = \&reaper
}
------------------------------
Date: Thu, 26 Jun 2003 14:54:32 +0800
From: "Bob Heye" <heye@v2tech.com>
Subject: problem when use debug perl in win2000 os
Message-Id: <bde59v$1ros$1@mail.cn99.com>
Hi,all
I have such a problem, someone can help me?
When I debug a program written in perl using "perl -d foo.pl"
The following message show up:
================================
Unable to connect to remote host: 127.0.0.1:2000
Compilation failed in require.
main::BEGIN() called at D:/Perl/5.8.0/lib/perl5db.pl line 0
eval {...} called at D:/Perl/5.8.0/lib/perl5db.pl line 0
BEGIN failed--compilation aborted.
================================
My OS is win2000, and the perl version is 5.8.0.
If I don't debug it, just run it ( perl foo.pl), everything is fine.
Any comments will be appreciated.
Regrads
BobH
------------------------------
Date: Thu, 26 Jun 2003 14:54:32 +0800
From: "Bob Heye" <heye@v2tech.com>
Subject: problem when use debug perl in win2000 os
Message-Id: <bde5b5$1rq2$1@mail.cn99.com>
Hi,all
I have such a problem, someone can help me?
When I debug a program written in perl using "perl -d foo.pl"
The following message show up:
================================
Unable to connect to remote host: 127.0.0.1:2000
Compilation failed in require.
main::BEGIN() called at D:/Perl/5.8.0/lib/perl5db.pl line 0
eval {...} called at D:/Perl/5.8.0/lib/perl5db.pl line 0
BEGIN failed--compilation aborted.
================================
My OS is win2000, and the perl version is 5.8.0.
If I don't debug it, just run it ( perl foo.pl), everything is fine.
Any comments will be appreciated.
Regrads
BobH
------------------------------
Date: Wed, 25 Jun 2003 20:59:07 -0700
From: "Jman" <james.mctiernan@rcn.com>
Subject: Re: search for messages in large files
Message-Id: <bddr1p$ot8$1@bob.news.rcn.net>
Actually, as I completely understand the contents of the file, and you do
not,
I am trying to explain what the contents of the file looks like, and have
not
changed my mind on anything. I was attempting to show how I have
tried to handle my task, like you requested. I thought that it would be
better to remove the control characters first, maybe this isn't necessary.
The "MSG" data that I mentioned in my original posting are the second to
last words on the first line of each message, e.g. TIME, SLC MDIIMON, etc...
Let's say I want to retrieve all of the MAINT messages from 03-06-13,
what is the best way to do it. Using my style I end up creating large
files,
against which I run another script against, creating another large file,
and running another script against it, until I finally get the data I want.
I would like to be able to run one script, looking for any day of the month
with a particular MSG.
If you can offer anything, thanks, if not thanks anyway
I am doing my best to explain
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news: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: 26 Jun 2003 04:25:16 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: search for messages in large files
Message-Id: <slrnbfktdc.ng4.sholden@flexal.cs.usyd.edu.au>
On Wed, 25 Jun 2003 20:59:07 -0700, Jman <james.mctiernan@rcn.com> wrote:
> Actually, as I completely understand the contents of the file, and you do
> not,
> I am trying to explain what the contents of the file looks like, and have
> not
> changed my mind on anything. I was attempting to show how I have
> tried to handle my task, like you requested. I thought that it would be
> better to remove the control characters first, maybe this isn't necessary.
> The "MSG" data that I mentioned in my original posting are the second to
> last words on the first line of each message, e.g. TIME, SLC MDIIMON, etc...
Of course, all the readers are psychic and knew that when you said "actually
MSG[1-50]", you didn't mean MSG1, MSG2, ..., MSG50 but of course meant
TIME, SLC, MDIIMON, etc...
How foolish of those of us who can't read minds.
--
Sam Holden
------------------------------
Date: 26 Jun 2003 05:07:09 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: search for messages in large files
Message-Id: <slrnbfkvs0.1hq.mgjv@verbruggen.comdyn.com.au>
[Don't top post]
On Wed, 25 Jun 2003 20:59:07 -0700,
Jman <james.mctiernan@rcn.com> wrote:
> Actually, as I completely understand the contents of the file, and you do
> not,
> I am trying to explain what the contents of the file looks like, and have
> not
> changed my mind on anything. I was attempting to show how I have
> tried to handle my task, like you requested. I thought that it would be
> better to remove the control characters first, maybe this isn't necessary.
> The "MSG" data that I mentioned in my original posting are the second to
> last words on the first line of each message, e.g. TIME, SLC MDIIMON, etc...
> Let's say I want to retrieve all of the MAINT messages from 03-06-13,
> what is the best way to do it. Using my style I end up creating large
> files,
How are we supposed to know that? You initially said something totally
different from what is in the actual data that you finally posted.
Your data does NOT contain any MSG followed by a number between 1 and
50 at all, but that is what you originally stated. I provided some
code to find that.
Then you post actual data that looks completely different, and I again
do my best to interpret what it is you mean from your half-arsed
specification (including modifying the data according to your
instructions), and again provide some code for you to start with.
All you do is whinge that you're not getting a complete solution to
your underspacified problem, instead of trying to clarify the
confusion that you, yourself, created in the first place.
> against which I run another script against, creating another large file,
> and running another script against it, until I finally get the data I want.
> I would like to be able to run one script, looking for any day of the month
> with a particular MSG.
> If you can offer anything, thanks, if not thanks anyway
> I am doing my best to explain
What was wrong with the suggestions I posted already? if you answer,
please realise that i will not be reading it anymore.
*plonk*
[SNIP of TOFU]
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
Trading Post Australia | rich salesperson.
|
------------------------------
Date: 25 Jun 2003 18:13:26 -0700
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: system("clear"); vs. system("cls");
Message-Id: <slrnbfkhi5.obk.tim@vegeta.ath.cx>
Buteo Lagopus graced us by uttering:
> 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.
clear is the command to clear the terminal screen in unix. cls is
the command to clear the screen in DOS/Win (as well as many other
older systems). Use whichever is appropriate for your system, if
need be.
> Is perldoc in error or is this an OS port issue? I'd hope this
> won't cause cross-platform problems.
>
> Any thoughts?
Any use of system() (or exec, or backticks) is *likely* to cause
cross-platform problems by its very nature. system() and its
relatives are shortcuts *outside* Perl's cross-platform
abstraction. Use sparingly. :)
HTH
Tim Hammerquist
--
Man is the only animal that blushes -- or needs to.
-- Mark Twain
------------------------------
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 5137
***************************************