[22618] in Perl-Users-Digest
Perl-Users Digest, Issue: 4839 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 13 06:06:02 2003
Date: Sun, 13 Apr 2003 03:05:06 -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 Sun, 13 Apr 2003 Volume: 10 Number: 4839
Today's topics:
Re: 64bit Perl <trh411@earthlink.net>
Re: Anyone else have cperl-mode problems? (Joe Brenner)
help with using Net-Telnet module.. <shayh@mpthrill.com>
Matching and capturing wide character strings in binary (Lauren Smith)
Shortcut <mail@annuna.com>
Re: Shortcut <jurgenex@hotmail.com>
Re: Shortcut <bwalton@rochester.rr.com>
Re: Shortcut <jurgenex@hotmail.com>
Re: Shortcut <wsegrave@mindspring.com>
slow/inefficient script: seeking help with multimatch/m (Adam)
Re: split question ctcgag@hotmail.com
Re: Stubbing FileHandle.pm (Stephen Deken)
What is wrong? <mail@annuna.com>
Re: What is wrong? <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Apr 2003 04:02:15 GMT
From: "Tom Hoffmann" <trh411@earthlink.net>
Subject: Re: 64bit Perl
Message-Id: <pan.2003.04.13.04.01.59.646120@earthlink.net>
On Wed, 09 Apr 2003 16:43:09 -0700, Edward A Thompson wrote:
> Trying to compile perl 5.8 on a Solaris 8 box that is 64 bit. Using the
> Forte compiler, I can get it to compile as 32 bit, but have trouble
> subsequntly compiling DBD:Oracle, since we have a 64bit Oracle install.
I had a similar problem on AIX w/ 64 bit Oracle trying to make DBD::Oracle.
I ended up modifying the Makefile to use the Oracle 32-bit libraries. That
is, I changed all references to the 64-bit Oracel lib (../lib) to the 32-bit
Oracle lib (../lib32). IIRC, I also had to change all refernces to ctr-64.o
to crt.o.
Hope this helps.
------------------------------
Date: Sun, 13 Apr 2003 05:52:37 +0000 (UTC)
From: doom@kzsu.stanford.edu (Joe Brenner)
Subject: Re: Anyone else have cperl-mode problems?
Message-Id: <b7atv4$l95$1@news.Stanford.EDU>
genericax@hotmail.com (Sara) writes:
>I have syntax highlighting on, and the entire file is highlighted, but
>any text I add goes in ALL BLACK. If I want the added text to be
>highlighted, I have to use
> C-x cperl-mode
>and botta-bing everything is highlighted again. In an average session
>I type this 30-50 times or more.
>On OTHER systems it works fine- pretty much highights as I type.
>I understand this may be an emacs question rather than perl, but in
>this case I'd like an actual answer. They're hard to come by in the
>emnacs/unix groups.
Not that I've ever noticed, actually. The folks at
comp.emacs have been pretty helpful (and there have been
a few recent threads talking about cperl-mode).
>This is gun-emacs 20.7.1 (sun-sparc-solaris2.8, x toolkit)
>running on Solaris, perl 5.6.1
I use emacs 21.1.1, on Linux myself, and I don't think I've
ever seen a problem like you describe. I'm using cperl mode
version "4.23". You can check the version by doing this:
Esc x help v cperl-version
It looks like the latest version of cperl-mode out there
is 4.32:
http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
It probably can't hurt to try upgrading. If you don't have
permissions to install stuff on your Solaris box, you can
always put it in a directory of your own, and put that
location at the front of your emacs load-path. For example,
I might put something like this in my .emacs:
(setq load-path
(append load-path
'("/home/doom/emacs-lib")))
If the latest version doesn't help, I would take a look at
changing the color scheme I was using in my emacs. Maybe
there's an unfortunate collision between the way you like
your colors set and the way cperl does things? A quick
way of looking for problems in your .emacs customizations
is to try running emacs with the '-q' flag... then you'll
know you're using the defaults.
And finally, here's some excerpts from my own .emacs that
might give you some hints as to what you'd want to try
playing with.
;;; setup cperl-mode
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
;;; (setq cperl-hairy t) ; ***BLEH! DO NOT USE***
;;; Fix obnoxious cperl-mode trailing-space highlighting.
(setq cperl-invalid-face (quote off))
;;; general emacs color scheme
; Provides a (base?) color scheme for additional frames:
(add-to-list 'default-frame-alist '(foreground-color . "Thistle"))
(add-to-list 'default-frame-alist '(background-color . "Black"))
(add-to-list 'default-frame-alist '(cursor-color . "Orchid"))
(add-to-list 'default-frame-alist '(mouse-color . "GreenYellow"))
(add-to-list 'default-frame-alist '(border-color . "DarkOliveGreen"))
(add-to-list 'default-frame-alist '(border-color . "Thistle"))
;Highlighting the region
(transient-mark-mode t)
(set-face-foreground 'region "Black")
(set-face-background 'region "DarkOliveGreen")
;hacking the rest of the color scheme:
(set-foreground-color "Thistle")
(set-background-color "Black")
(set-cursor-color "Orchid")
(set-mouse-color "GreenYellow")
(set-face-foreground 'modeline "Black")
(set-face-background 'modeline "DarkSlateBlue")
; Does this do anything?
(set-border-color "DarkOliveGreen")
; This sets the text color for highlighted text (e.g. when running ispell)
(set-face-foreground 'highlight "PaleGreen")
(set-face-background 'highlight "BlueViolet")
(show-paren-mode)
(set-face-foreground 'show-paren-match-face "PaleGreen")
(set-face-background 'show-paren-match-face "BlueViolet")
(set-face-foreground 'show-paren-mismatch-face "yellow")
(set-face-background 'show-paren-mismatch-face "firebrick")
; Experimenting with just turning on font-lock everywhere
(global-font-lock-mode 1)
------------------------------
Date: Sun, 13 Apr 2003 12:09:24 +0200
From: "Shay Hugi" <shayh@mpthrill.com>
Subject: help with using Net-Telnet module..
Message-Id: <3e992a42@news.012.net.il>
Hi,
I would like to use net-telnet to collect information on some of our network
equipments,
right now i'm working with a vb script that starts a telnet session (run a
few commands) and saves the session as a text file.
i want to replace this vb script with a perl script that does the same, all
i need is a few lines of example on how to do it...
including the part of saving the telnet session as a text file (it should
overwrite the file if exist and not append it)
currently i work as script per network equipment, instead of writing an
external array that reads the network nodes information and post them in one
script.
i would like to stay in this way for some reasons that are related to the
data collection and the types of network nodes i monitor.
i'm looking for a script where i could have simple arguments such as
"collect.pl 127.0.0.1 log.txt" and it will take the data according to the
commands written in the script and write them into log.txt...
if someone already wrote something similar i'll be happy to get it (it's not
a problem for me to change the script, it's just i need the basic beginning)
Thanks in advance everybody!
Shay Hugi
Golden-Channles
------------------------------
Date: 13 Apr 2003 00:28:57 -0700
From: lauren_smith13@hotmail.com (Lauren Smith)
Subject: Matching and capturing wide character strings in binary files
Message-Id: <abee5678.0304122328.4b937db0@posting.google.com>
I am having trouble matching a multi-byte character string in a binary
file.
I have a compiled binary executable that contains zero or more wide
character strings of a specific format. I would like to match and
extract the string. Unfortunately for me, nothing seems to work.
If the strings were normal ASCII, I would use something like this:
#!perl -w
open FILE, "my.bin" or die "my.bin: $!";
binmode FILE;
$data = "foo"
while (<FILE>) {
print "found" if /$data/;
}
I ran this on the binary searching for a known 8-bit character string
and the script found all instances of the string. It is likely that I
am missing some key point, but I believe this script to be correct.
Since I really want to find a string composed of wide characters, I
changed the encoding of $data to "UTF16" and performed the same search
on the file:
#!perl -w
use Encode;
open FILE, "my.bin" or die "my.bin: $!";
binmode FILE;
$data = encode("UTF16", "bar");
while (<FILE>) {
print "found if /$data/;
}
This version of the script does not find $data. I have manually
verified that the wide character string "bar" is in the binary file,
so something must be wrong with my script.
Does it make sense to change the encoding on the binary file to UTF16
or somesuch? I'm not sure that it does. There are strings of various
formats in the file, as well as machine instructions that do not have
any logical meaning if encoded.
So this is where I am stuck. How can I match the string that I want?
Eventually I would like to capture some data that surrounds the string
something like '/MyStringMarker : <(.*?)>/', except that the match
would be on wide characters instead of 8-bit chars.
Any help would be greatly appreciated.
------------------------------
Date: Sat, 12 Apr 2003 20:59:24 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Shortcut
Message-Id: <3E98C47C.9080609@annuna.com>
what is the shortcut for swapping likew this this I can't seem to find it.
$c = $a;
$a = $b;
$b = $c;
------------------------------
Date: Sun, 13 Apr 2003 03:14:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Shortcut
Message-Id: <gC4ma.1549$ok3.1406@nwrddc03.gnilink.net>
Joe Creaney wrote:
> what is the shortcut for swapping likew this this I can't seem to
> find it.
>
> $c = $a;
> $a = $b;
> $b = $c;
If you just want to swap the values of $a and $b then simply
($a, $b) = ($b, $a);
If you care about $c, too, then
($a, $b, $c) = ($b, $a, $a);
jue
------------------------------
Date: Sun, 13 Apr 2003 03:55:18 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Shortcut
Message-Id: <3E98DF62.6030807@rochester.rr.com>
Joe Creaney wrote:
> what is the shortcut for swapping likew this this I can't seem to find it.
>
> $c = $a;
> $a = $b;
> $b = $c;
>
($c,$a,$b)=($a,$b,$c);
except that will preserve the original contents of $c, where your code
above will lose it.
--
Bob Walton
------------------------------
Date: Sun, 13 Apr 2003 04:18:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Shortcut
Message-Id: <ly5ma.8739$U34.2559@nwrddc02.gnilink.net>
Bob Walton wrote:
> Joe Creaney wrote:
>
>> what is the shortcut for swapping likew this this I can't seem to
>> find it.
>>
>> $c = $a;
>> $a = $b;
>> $b = $c;
>>
>
> ($c,$a,$b)=($a,$b,$c);
Actually no.
In the code from the OP the new value of $b would be the original value of
$a while with your code the new value of $b will be the original value of
$c.
> except that will preserve the original contents of $c, where your code
> above will lose it.
No. $c will be overwritten with the value of $a, it does not preserve it's
value.
jue
Actull
------------------------------
Date: Sun, 13 Apr 2003 00:35:01 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Shortcut
Message-Id: <b7asvn$f0b$1@slb9.atl.mindspring.net>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:gC4ma.1549$ok3.1406@nwrddc03.gnilink.net...
> Joe Creaney wrote:
> > what is the shortcut for swapping likew this this I can't seem to
> > find it.
> >
> > $c = $a;
> > $a = $b;
> > $b = $c;
<snip>
> If you care about $c, too, then
> ($a, $b, $c) = ($b, $a, $a);
Jue, I think the OP may be simply trying to rotate the elements of the array
($a,$b,$c) cyclicly by moving the third element to the first position, e.g.,
My code
# rotate.pl
use strict;
my ($a,$b,$c);
$a='one';
$b='two';
$c='three';
# one way to do it
($a,$b,$c)=($c,$a,$b);
print join(', ',($a,$b,$c)), "\n";
#another way to do it
my @i=($a,$b,$c);
my $i = pop @i;
unshift(@i,$i);
print join(', ', @i);
prints
three, one, two
two, three, one
while your code
($a,$b,$c)=($b,$a,$a)
prints
two, one, one
Perhaps we have not interpreted the OP's problem the same way? Or maybe I
don't understand what you were trying to do?
Cheers.
Bill Segraves
------------------------------
Date: Sun, 13 Apr 2003 04:14:53 GMT
From: pls@post.here (Adam)
Subject: slow/inefficient script: seeking help with multimatch/multipass pattern matching
Message-Id: <qnoh9v8l3b4k341vf902lmg3c2ukciohq6@4ax.com>
Hello,
I am looking for the fastest way to access lines in a sendmail log
file. I've written the script (at the bottom of this post) because
the helpdesk/users often ask me (the mail gateway guy) to look up
email problems for user X on "Mth Day." So what I first need to do
is grep for that user's name. Either the from= or the to= will have
the pattern *but it won't be in both*. I then need to build a list of
Message ID's (using the FAQ's qr() example) from the matches and,
using that list, pass again through the file and "grep" both the "to"
and the "from" (which is what we need to troubleshoot email problems).
The script I have below works (yipee!) but is 3 times slower than
egrep and awk in a loop :(
Ideally I'd like to fix my own script instead of using a solution you
may post since I wrote this one and thus can understand and maintain
it. Every time I look at it I want to do something like save the
lines on the 1st pass but that is no good because I've got to go back
and get the 2nd line of the conversation (the line not containing the
name pattern - could be the from or to). The lines are almost never
contiguous and if it is a bounce or DSN there will be more than just
the from/to.
My test data file ran quickly enough but the real file is 500K + lines
(and it's not even mid-month). Where is the bottle neck? I don't
think it is the 1st pass as I added print statements and those came
pretty fast. Also the final list (in the sorted hash) is usually only
20-30 lines so I don't think the sorted hash is the slow-down. By the
way, I added that sorted hash becuase the pattern matching was
printing out lines with multiple email addresses
(to=<bob@bob.com>,<sue@sue.com>) multiple times. So the sorted hash
removes dupes for me - if you know of a better way (or why it catches
it twice when the pattern is on that line only once...), please let me
know but the script was slow even before I added the sorted-hash. So
the problem is in the middle bit where I break the pattern up into $1,
$2, $3, etc. I added the " next unless ($match =~ /$date...." bit
right after the beginning "while <LOG>" thinking that would stop the
program from looking at all the other days and that helped but it is
still taking 3min for a user in the middle of a 500K file whereas a
ksh/egrep/awk loop took 50seconds.
So I am humbly asking for either redesign/rethinking suggestions
(maybe my approach is the inefficient part) or maybe some perl blunder
in my code is slowing me down.
much thanks for any advice or suggestions,
Adam
====================================
#!/usr/local/bin/perl -w
$maillog="/tmp/mail";
if ( $#ARGV == 2 ) {
$name = $ARGV[0];
$month = $ARGV[1];
$day = $ARGV[2];
}
elsif ( $#ARGV == 1 ) {
$name = $ARGV[0];
$month = $ARGV[1];
$day = 0;
}
elsif ( $#ARGV == 0 ) {
$name = $ARGV[0];
($month, $day ) = (split( /\s+/, scalar(localtime)))[ 1, 2 ];
}
else {
print "Usage: $0 name [Month] [Day]\n";
exit;
}
if ($day == 0 ) { $date = $month . " " ; }
if ($day > 9 ) { $date = $month . " " . "$day"; }
if ($day <= 9 ) { $date = $month . " " . "$day"; }
open(LOG,$maillog) || die "cannot open $maillog: $!";
while ( my $match = <LOG> )
{
next unless ($match =~ /$date.*?]: (\w+)?: (from|to).*?$name/i );
push(@mailids,$1);
} # end of while my match = <LOG>
@mailpats = map { qr/\b$_\b/i } @mailids;
open(LOG,$maillog) || die "cannot open $maillog: $!";
while ( my $match = <LOG> ) {
next unless ($match =~ /$date.*?]: \w+?: (from|to)/i );
for $patobj (@mailpats) {
if ($match =~ /$patobj/) {
if ($match =~ /from=</ ) {
$match =~ m/(\w+?\s+\d+?\s+) # $1 Month Day
\d+?:\d+?:\d+?\s+ # Timestamp HH:MM:SS
\w+?\s+sm-mta-\w+? # server MTA
\[\d+?\]:\s+? # process ID
(\w+)?:\s+? # $2 sendmail mailq or log id
from=<(.*)>.*? # $3 capture the name
\s+relay=(.*?\s+?\S+?) # $4 catch relay names
\s+(.*)/ix; # ignore the rest for now
$fromline = "$1 $2 from=$3 relay=$4\n";
$hashkey = $2 . "frm";
$logline_hash{$hashkey} = $fromline;
} # end if match from
elsif ($match =~ /to=</ ) {
$match =~ m/(\w+?\s+\d+?\s+) # $1 Month Day
\d+?:\d+?:\d+?\s+ # Timestamp HH:MM:SS
\w+?\s+sm-mta-\w+? # server MTA
\[\d+?\]:\s+? # process ID
(\w+)?:\s+? # $2 sendmail mailq or log id
to=<(.*)>.*? # $3 capture multiples names
relay=(.*?)\s+.*? # $4 catch relay name
\s+stat=(.*?\s+?\S+?) # $5 stat (OK) or other 2nd arg
\s+.*/ix; #
$toline = "$1 $2 to=$3 relay=$4 stat=$5\n";
$hashkey = $2 . "to";
$logline_hash{$hashkey} = $toline;
} # end if match to
} # end if match =~ /$patobj/
} # end for $patobj (@mailpats)
} # end while
print "\nExtract by name\n=====================\n";
foreach(sort keys %logline_hash) {
$tmpvar = $_;
chomp($tmpvar);
print "$logline_hash{$_}";
}
------------------------------
Date: 13 Apr 2003 03:45:24 GMT
From: ctcgag@hotmail.com
Subject: Re: split question
Message-Id: <20030412234524.894$qy@newsreader.com>
bruno@Skorepa.com (Bruno Skorepa) wrote:
>
>
> If there is a comma in one of the columns, Excel puts the data within
> "..."
> for example:
>
> 370,SKF,4/3/2003,Warteliste,"termin editieren, pat wählen",,,,,,
>
> If there is a " within the data, Excel escapes that by a second one:
> for example:
>
> 377,Dorfinger,4/15/2003,WinMed,"Der Cursor bleibt beim
> Fensterverschieben ""kleben"", so daß man oft ungewollt das Fenster
> verschiebt",,,,,,
>
> can this be done with one split command?
my @x = split /,(?=[^"]*(?:"[^"]*"[^"]*)*$)/ ;
This will do the split, but it won't undouble the inner quotes
or strip the outer ones.
(Although you really should use modules, as others have recommended.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 12 Apr 2003 23:18:39 -0700
From: google@awdang.com (Stephen Deken)
Subject: Re: Stubbing FileHandle.pm
Message-Id: <d6ccc926.0304122218.6eec39ac@posting.google.com>
Steve Grazzini wrote:
> Since you don't use any of the IO::* methods, why not just
> get rid of the dependency altogether?
>
> open(my $fh, $filename) or die "open: '$filename': $!";
Because under Perl 5.005_03 symbol globbing, file handles, or
something else unrelated was treated differently and this trick
doesn't work. I happen to be embedding Perl 5.8.0 in this
application, but the code is shared with a server that runs Perl
5.005_03, and since the idea is to have a single codebase, I can't use
this rather nifty enhancement.
Yes, I know I should just upgrade the server, but that's not an option
right now.
--sjd;
------------------------------
Date: Sat, 12 Apr 2003 20:43:50 -0500
From: Joe Creaney <mail@annuna.com>
Subject: What is wrong?
Message-Id: <3E98C0D6.8080505@annuna.com>
What is wrong here, I get a syntax error here at my package main then it
says not BEGIN not safe after errors
Here is my code.
$mm[2] = $hp;
while ($num[$lp]->name ne " "){
if ($num[$lp]->{name} eq " ") {
$num[$lp] = new (@mm, $mx, $my );
$lp++;
}
}
$v = $num[$lp];
return $v, $player;
}
package Map; <-- Error here
#!/usr/bin/perl -w
use strict; <-- Error here
new {
------------------------------
Date: Sun, 13 Apr 2003 03:22:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What is wrong?
Message-Id: <RJ4ma.1550$ok3.537@nwrddc03.gnilink.net>
Joe Creaney wrote:
> What is wrong here, I get a syntax error here at my package main then
Why don't you just read(!) what the error message says:
"Unmatched right curly bracket at ....."
> it says not BEGIN not safe after errors
>
> Here is my code.
>
> $mm[2] = $hp;
> while ($num[$lp]->name ne " "){
Open one
> if ($num[$lp]->{name} eq " ") {
Open two
> $num[$lp] = new (@mm, $mx, $my );
> $lp++;
> }
Close one
> }
Close two
> $v = $num[$lp];
> return $v, $player;
>
> }
Close three????
>
> package Map; <-- Error here
No, it's the line above
> #!/usr/bin/perl -w
> use strict; <-- Error here
Really? My compiler doesn't even get that far.
>
> new {
jue
------------------------------
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 4839
***************************************