[21871] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4075 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 6 18:11:53 2002

Date: Wed, 6 Nov 2002 15:10:17 -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           Wed, 6 Nov 2002     Volume: 10 Number: 4075

Today's topics:
        insert difficulty (Benjamin Zhou)
    Re: insert difficulty <ak@freeshell.org.REMOVE>
    Re: insert difficulty <pinyaj@rpi.edu>
    Re: insert difficulty <usenet@dwall.fastmail.fm>
    Re: insert difficulty (Tad McClellan)
    Re: insert difficulty <ak@freeshell.org.REMOVE>
        itreads and dbmopen <cliff@may.be>
        Perl docs and FAQ (was Re: Unix command) <usenet@dwall.fastmail.fm>
    Re: Q re eval nobull@mail.com
    Re: regex or substr or both? <perl-dvd@ldschat.com>
    Re: regex or substr or both? <perl-dvd@ldschat.com>
        Returning matches in an array (emcee)
    Re: Returning matches in an array (Tad McClellan)
    Re: saving regex results <matt@no.spam.please>
        Script is skipping chapters... (Andrew Burton)
    Re: Script is skipping chapters... <ak@freeshell.org.REMOVE>
    Re: Script is skipping chapters... (Andrew Burton)
    Re: Simple question - What is unicode? <flavell@mail.cern.ch>
    Re: special characters in command-line (Stuart Kendrick)
    Re: special characters in command-line (Stuart Kendrick)
    Re: Unix command stan@temple.edu
    Re: Unix command  support@gethits22.com
        Using SNMP::Multi Modul: putt responses to hash?! (Jens Abromeit)
        Win32 and unicode (emcee)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 Nov 2002 12:34:01 -0800
From: bzhou@pfs.com (Benjamin Zhou)
Subject: insert difficulty
Message-Id: <f6572006.0211061234.70384479@posting.google.com>

Hi,

I need to convert strings like "WeMustInsert" into "We_Must_Insert".
the code I tried:

$str = "WeMustInsert";
$str =~ s/[a-z][A-Z]/[a-z]_[A-Z]/g;
print $str;

But I got the following result: "W[a-z]_[A-Z]us[a-z]_[A-Z]nsert".
it looks like s/// can't be used for insert. But where should I proceed?

thanks a lot for any tip.
Ben


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

Date: Wed, 06 Nov 2002 20:52:20 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: insert difficulty
Message-Id: <slrnasj073.208.ak@otaku.freeshell.org>

Submitted by "Benjamin Zhou" to comp.lang.perl.misc:
> Hi,
> 
> I need to convert strings like "WeMustInsert" into "We_Must_Insert".
> the code I tried:
> 
> $str = "WeMustInsert";
> $str =~ s/[a-z][A-Z]/[a-z]_[A-Z]/g;
> print $str;
> 
> But I got the following result: "W[a-z]_[A-Z]us[a-z]_[A-Z]nsert".
> it looks like s/// can't be used for insert. But where should I proceed?
> 
> thanks a lot for any tip.
> Ben

The replacement text is never a regular expression.

Do this instead:

$str =~ s/([a-z])([A-Z])/\1_\2/g;

-- 
Andreas Kähäri               --==::{ Have a Unix: netbsd.org
                             --==::{ This post ends with :wq


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

Date: Wed, 6 Nov 2002 15:58:26 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Benjamin Zhou <bzhou@pfs.com>
Subject: Re: insert difficulty
Message-Id: <Pine.A41.3.96.1021106155653.43976A-100000@cortez.sss.rpi.edu>

[posted & mailed]

On 6 Nov 2002, Benjamin Zhou wrote:

>$str = "WeMustInsert";
>$str =~ s/[a-z][A-Z]/[a-z]_[A-Z]/g;
>print $str;

Close.  You need to capture the letters and replace them with themselves:

  s/([a-z])([A-Z])/$1_$2/g;

Or:

  s/(?<=[a-z])(?=[A-Z])/_/g;

That second regex means "if I'm preceded by [a-z] and followed by [A-Z],
put a _ there."

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Wed, 06 Nov 2002 21:05:39 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: insert difficulty
Message-Id: <Xns92BEA3B83F6Edkwwashere@216.168.3.30>

Benjamin Zhou <bzhou@pfs.com> wrote on 06 Nov 2002:

> I need to convert strings like "WeMustInsert" into "We_Must_Insert".
> the code I tried:
> 

Ask perl to help you as much as it can:  

    use strict;
    use warnings;

(Admittedly, it wouldn't have helped here, because even though you didn't 
get what you wanted, your code is perfectly valid Perl.)

> $str = "WeMustInsert";
> $str =~ s/[a-z][A-Z]/[a-z]_[A-Z]/g;

This says to perl, "whenever you find a lowercase character followed by an 
uppercase character, replace them both with the string '[a-z]_[A-Z]'"

> print $str;
> 
> But I got the following result: "W[a-z]_[A-Z]us[a-z]_[A-Z]nsert".
> it looks like s/// can't be used for insert. But where should I proceed?

It looks like some stuff got inserted to me -- just not what you expected.

Quoting myself from earlier today:

<quote>
Rather than just rewriting your code for you, here's where you can learn 
for yourself:  

perldoc perlrequick
perldoc perlretut
perldoc perlre

In perlrequick, look at the section "Extracting matches".  In short: use 
grouping parentheses and the dollar-number variables ($1, $2, ...).
</quote>

and also see perlop for the section on s/PATTERN/REPLACEMENT/egimosx

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Wed, 6 Nov 2002 16:12:40 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: insert difficulty
Message-Id: <slrnasj4uo.24c.tadmc@magna.augustmail.com>

Andreas Kähäri <ak@freeshell.org.REMOVE> wrote:

> $str =~ s/([a-z])([A-Z])/\1_\2/g;
                           ^  ^
                           ^  ^

You should always enable warnings when developing Perl code.


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


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

Date: Wed, 06 Nov 2002 22:23:03 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: insert difficulty
Message-Id: <slrnasj5h6.208.ak@otaku.freeshell.org>

Submitted by "Tad McClellan" to comp.lang.perl.misc:
> Andreas Kähäri <ak@freeshell.org.REMOVE> wrote:
> 
>> $str =~ s/([a-z])([A-Z])/\1_\2/g;
>                            ^  ^
>                            ^  ^
> 
> You should always enable warnings when developing Perl code.
> 
> 

Aw, bugger.  I've been doing too much work with other regex
tools lately...

-- 
Andreas Kähäri               --==::{ Have a Unix: netbsd.org
                             --==::{ This post ends with :wq


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

Date: Wed, 6 Nov 2002 21:19:58 +0100
From: Cliff Stanford <cliff@may.be>
Subject: itreads and dbmopen
Message-Id: <Pk1xVwRulXy9EwOG@mail.co.uk>

I am using a multi-threaded program and need to preserve data between 
invocations.  I have a shared hash (our %status : shared) which is only 
written to from one thread but is read in another.  I am therefore not 
locking it before read or write.

If I run the program without dbmopen'ing the hash, it works perfectly. 
If I do a dbmopen on the hash before creating the threads, again it 
works but, when the threads exit and are joined, I get a Segmentation 
Fault.  If I re-run the program, the data is recovered.

Is dbmopen supported on shared hashes?  Anyone any guesses as to why 
it's sigsegv'ing?

All suggestions for tracking down the problem appreciated.  It's running 
on RedHat Linux 7.2 with a 2.4.9 kernel.

Thanks,
Cliff.
-- 
Cliff Stanford                             http://www.redbus.co.uk/
Redbus Management Limited                  +44 20 7257 2000 (Office)
17-18 Henrietta Street                     +44 7973 616 666 (Mobile)
London  WC2E 8QH


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

Date: Wed, 06 Nov 2002 20:25:26 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Perl docs and FAQ (was Re: Unix command)
Message-Id: <Xns92BE9CE69234Cdkwwashere@216.168.3.30>

 <ry@yokoyama.ws> wrote on 06 Nov 2002:

> Thanks for people answering my question.  I did not konw perldoc.  I 
> will read it.

'perldoc' is the program/command used to read the Perl documentation.  With 
a proper installation of Perl, you can type 

perldoc perldoc

at a command line to get more information about it.  If you're on Windows 
(seems likely -- you're using a Windows newsreader), Activestate Perl comes 
with the Perl docs in HTML format as well; by default it puts a shortcut in 
the Start menu.  But perldoc is still useful for lookups of functions, 
FAQs, etc.

 
> I have another question. Is there FAQ?  If so, could you tell me where I 
> can find it.

There is most definitely a FAQ list.

perldoc perlfaq

You can also find docs online at www.perldoc.com, although the docs that 
comes with Perl are always the most up-to-date or relevant to the copy of 
Perl you're using.  (and probably the most convenient as well: you don't 
have to be online to use them)

There are also good suggestions for posting to comp.lang.perl.misc at 
http://mail.augustmail.com/~tadmc/clpmisc.shtml.  I'm pointing you -- and 
potential lurkers -- to them as (I hope) a helpful hint, not a flame.

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: 6 Nov 2002 11:31:25 -0800
From: nobull@mail.com
Subject: Re: Q re eval
Message-Id: <4dafc536.0211061131.6a65ea18@posting.google.com>

"Tan Nguyen" <nospam@nospam.com> wrote in message news:<3dc5e02e_6@nopics.sjc>...
> "Dick Penny" <penny1482@attbi.com> wrote in message
> news:9Yjx9.60657$bt.109544@rwcrnsc52.ops.asp.att.net...
> > If  I have a text file with simple Perl expressions, one per line, in
>  terms
> > of variables, say
> > $ma1*.47 + $p[2] > .3*$ma2
> > can I read this in at execute time and "eval" it to TRUE or FALSE
>  depending
> > on the value of the variables at that instant?
> Well, try it before you post. It should work as you expect.

This is true but it may still be worth considering alternatives.
 
> > If not, is there a technique to do this task?

One alternative is the Safe module.  This provides a degree of
firewalling between your script and the code in the text file.  This
is good if you do not completely trust the person writing the "text
file" to execte arbitrary Perl code on your machine.

If, on the other hand, you do completely trust the person writing the
"text file" to execte arbitrary Perl code on your machine then you
should consider turning the problem inside out.  Make what is now your
script into a module.  Make the "text file" into a perl script.

One possible way this could look...

#!/usr/bin/perl
use strict;
use warnings;
use MyModule; # Exports &condition @p $ma1 etc.
# prototype(&condition) == (&)

condition { $ma1*.47 + $p[2] > .3*$ma2 };
condition { $ma3* .6 + $p[0] > $ma1 }; 
__END__

I have gone the "text file" way several times in the past and regetted
it.  I now _strongly_ council people to think thrice before starting
down that particular road no matter how tempting it appears.


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

Date: Wed, 6 Nov 2002 13:44:43 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: regex or substr or both?
Message-Id: <a4fy9.21070$46.10465@fe01>

"Lance Hoffmeyer" <lance@augustmail.com> wrote in message
news:pan.2002.11.06.18.28.38.162696.2546@augustmail.com...
> given a file (test.txt):
>
> line 1
> line 2
> line 3
> Table 1
> line 5
> line 6
> Male
> 10 25 35
> line 9
> Table 2
> line 5
> line 6
> Female
> 11 35 45
> line 9
>
> I originally planed to create a series of regex's to find and
extract
> the number '35' from the file.  Now I am wondering if using substr
and
> regex's would be better because I know that the number 35 (more
> specifically, the second number on the line below 'Male') is always
in
> a substring below Table 1 and Male.  What is the most efficient way
> of handling this task: regex; substr; both; something else?
>
> My original plan.
>
> open(FILE,<gender.txt>);
>
> series of regex to extract from line 8 the number 35
>
> close(FILE);


This gets you what you want pretty quick and easy:

#########################################
open(FILE, "</file/path/gender.txt");
my $file;
{local $/=undef;$file=<>}
close(FILE);

# if you intend to just find the number HERE:
# -------------------------------------------
$file =~ /Table 1.*?Male.*?\d+\D+(\d+)/s;
# find "Table 1" then the very next occurence of "Male", then the
# very next digit (1 or more that is), then a non-digit (1 or more)
# then assigns the one or more digits after that to $1 , Note the
# s on the end, thats how span multiple lines
my $second_number = $1;

# if you intend to replace that number HERE:
# -------------------------------------------
my $replacement = "this replaces the second number";
$file =~ s/(Table 1.*?Male.*?\d+\D+)\d+/$1$replacement/s;
#########################################

Regards,
David






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

Date: Wed, 6 Nov 2002 13:48:13 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: regex or substr or both?
Message-Id: <n7fy9.21073$46.15759@fe01>

Sorry, Type-o, see below

"David" <perl-dvd@ldschat.com> wrote in message
news:a4fy9.21070$46.10465@fe01...
> "Lance Hoffmeyer" <lance@augustmail.com> wrote in message
> news:pan.2002.11.06.18.28.38.162696.2546@augustmail.com...
> > given a file (test.txt):
> >
> > line 1
> > line 2
> > line 3
> > Table 1
> > line 5
> > line 6
> > Male
> > 10 25 35
> > line 9
> > Table 2
> > line 5
> > line 6
> > Female
> > 11 35 45
> > line 9
> >
> > I originally planed to create a series of regex's to find and
> extract
> > the number '35' from the file.  Now I am wondering if using substr
> and
> > regex's would be better because I know that the number 35 (more
> > specifically, the second number on the line below 'Male') is
always
> in
> > a substring below Table 1 and Male.  What is the most efficient
way
> > of handling this task: regex; substr; both; something else?
> >
> > My original plan.
> >
> > open(FILE,<gender.txt>);
> >
> > series of regex to extract from line 8 the number 35
> >
> > close(FILE);
>
>
> This gets you what you want pretty quick and easy:
>
> #########################################
> open(FILE, "</file/path/gender.txt");
> my $file;
> {local $/=undef;$file=<>}

Sorry, I for got to put the file handle in here.  It should be like
this
{local $/=undef;$file=<FILE>}
rather than
{local $/=undef;$file=<>}

By the way setting $/=undef causes the whole file to be slurped into a
scalar instead of an array.

> close(FILE);
>
> # if you intend to just find the number HERE:
> # -------------------------------------------
> $file =~ /Table 1.*?Male.*?\d+\D+(\d+)/s;
> # find "Table 1" then the very next occurence of "Male", then the
> # very next digit (1 or more that is), then a non-digit (1 or more)
> # then assigns the one or more digits after that to $1 , Note the
> # s on the end, thats how span multiple lines
> my $second_number = $1;
>
> # if you intend to replace that number HERE:
> # -------------------------------------------
> my $replacement = "this replaces the second number";
> $file =~ s/(Table 1.*?Male.*?\d+\D+)\d+/$1$replacement/s;
> #########################################
>
> Regards,
> David
>
>
>
>





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

Date: 6 Nov 2002 11:32:24 -0800
From: emcee@inorbit.com (emcee)
Subject: Returning matches in an array
Message-Id: <4fac3c33.0211061132.79d7ea53@posting.google.com>

Is there someway of returning every match for a regex in an array
rather than individual matches in varibles such as $1, $2 and so on?
The only way I can do it is to run a loop that finds a match than
split the original string at that match, combine all the varibles
after the first in the array into a single varible and splitting that.
But this seem like alot of extra trouble, is this the only way of
doing it?


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

Date: Wed, 6 Nov 2002 16:02:18 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Returning matches in an array
Message-Id: <slrnasj4ba.24c.tadmc@magna.augustmail.com>

emcee <emcee@inorbit.com> wrote:
> Is there someway of returning every match for a regex in an array
> rather than individual matches in varibles such as $1, $2 and so on?


Yes.

A pattern match will return all of the pattern memories
when you use it in list context.


eg:

   my @matches = $str =~ /(.)stuff(.)/;


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


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

Date: Wed, 06 Nov 2002 19:36:01 GMT
From: "matt" <matt@no.spam.please>
Subject: Re: saving regex results
Message-Id: <Aaey9.37053$Lu1.43000@sccrnsc01>


"Lance Hoffmeyer" <lance@augustmail.com> wrote in message
news:pan.2002.11.06.16.48.07.936122.2546@augustmail.com...
> I am having some problems with simple rexex stuff.
>
> Given a file:
>
> NOthing on this line
> Nothing on this line
> Find this line 1
> Table 167
> Nothing on this line
> Find this line 2
> Nothing on this line
> Nothing on this line
>
> If I try
> $target3 =~ m/TABLE.*/;
> print $target3;
>
> I expect "Table 167" to be printed but get nothing.

What are you trying to do? Print if $target3 matches 'Table'? You need
something like:

while (<FILE>) { print if m/Table/; }

Also, m/TABLE/ will not match 'Table'. You need the /i (case insensitive)
option for that, ie., m/TABLE/i;

-- Matt




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

Date: 06 Nov 2002 22:09:14 GMT
From: tuglyraisin@aol.commune (Andrew Burton)
Subject: Script is skipping chapters...
Message-Id: <20021106170914.11187.00004351@mb-fi.aol.com>

I'm stumped! I mean, I am really stumped...  I wrote a script to convert a text
file into an HTML file -- change breaks to the <br> tags and such -- and half
of it works.  What half you ask...  The even half.  I have a regular expression
that looks for "Chapter " ("Chapter" and a single space) in a line and then
makes that line bold.  It works too, but it skips the odd chapters.  I have run
a grep for "Chapter 77" (on my FreeBSD machine) and Find (on my Windows2000)
macine, so I know these chapters exist, and these chapter headers are even
found when looked for.  My script just misses them.  The file is 2.8MB, but I
thought Perl could handle that.  As said, I have run this on Windows2000
(ActivePerl 5.6.1) and FreeBSD 4.0 (Perl 5.8).  For whatever it's worth, I'm
trying to convert the text file of "Cryptonomicon" from textz.org -- in case
someone knows of tricks they use.  Any help would be appreciated.  Thanks.

---

use strict;

my $file = @ARGV[0];
my $line;

if ($file =~ m/\\/) {
	my @splfile = split (/\\/, $file);
	my $splfile = @splfile;
	$file = $splfile[$splfile-1];
}

open ("ain", "@ARGV[0]");
open ("aout", ">$file\.html");

print aout "<html><head><title> $file </title></head><body>\n";

while (<ain>) {
	$line = <ain>;
	$line =~ s/\n//g;

	if (($line =~ m/Chapter /) || ($line =~ m/Prologue/)){
		print aout "<b>$line</b><br><br>\n";
		print "$line\r\n";
	}
	elsif ($line ne "") {
		print aout "$line<br><br>\n";
	}
}

print aout "</body></html>";

close ("aout");
close ("ain");

print "$file has been converted.\n";

exit;

Andrew Burton -- tuglyraisin at aol dot com
Felecia Station on Harvestgain
"well, it's software, it can do anything :-)" - Ankh
"A racist alien robot, now that's cutting-edge children's programming, screw
the AIDS puppets." - Derik Smith



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

Date: Wed, 06 Nov 2002 22:20:34 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: Script is skipping chapters...
Message-Id: <slrnasj5ci.208.ak@otaku.freeshell.org>

Submitted by "Andrew Burton" to comp.lang.perl.misc:
[cut]
> 
> while (<ain>) {
> 	$line = <ain>;
> 	$line =~ s/\n//g;

You're reading in a line with the <ain> in the while conditional
statement, before reading in the next line nto $line.

better to do this:

while (defined($line = <ain>)) {
    chomp($line);




-- 
Andreas Kähäri               --==::{ Have a Unix: netbsd.org
                             --==::{ This post ends with :wq


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

Date: 06 Nov 2002 22:27:05 GMT
From: tuglyraisin@aol.commune (Andrew Burton)
Subject: Re: Script is skipping chapters...
Message-Id: <20021106172705.11159.00004284@mb-fi.aol.com>

> You're reading in a line with the <ain> in
> the while conditional statement, before 
> reading in the next line nto $line.

THANK YOU!  I try to be cute and use this is what happens.  Thank you again. :)



Andrew Burton -- tuglyraisin at aol dot com
Felecia Station on Harvestgain
"well, it's software, it can do anything :-)" - Ankh
"A racist alien robot, now that's cutting-edge children's programming, screw
the AIDS puppets." - Derik Smith



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

Date: Wed, 6 Nov 2002 20:39:15 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Simple question - What is unicode?
Message-Id: <Pine.LNX.4.40.0211062016000.15931-100000@lxplus075.cern.ch>

On Nov 6, W K inscribed on the eternal scroll:

> Helgi Briem <helgi@decode.is> wrote

> > Unicode is a scheme for encoding alphabets

Not exactly.  Unicode assigns numerical values to characters, but
there are numerous ways (several of which are in active use) of
actually encoding those numerical values to represent a character.

> > other than
> > the Latin by encoding each character with 2 bytes instead
> > of 1.

Some confusion here.

> All latin-1 and ascii have the same numerical values in unicode,

Yes

> BUT are now represented by two bytes instead of one.

That depends on the coding chosen.[1]

The problem here is that many folks coming to Unicode for the first
time have a background only in 8-bit character codings, where it's
obvious that once the characters have been identified by the numerical
values 0-255 you can represent them by the correspondingly-valued
octet (byte), end of story.  So there is no distinction between the
character code (i.e the assignment of characters to smallish integers)
and the character encoding scheme (the bit-patterns used to transmit
those integers).  In Unicode you cannot get away with that: it's
necessary to observe the distinction.

Note that recent versions of Unicode have more characters than can be
represented by a 16-bit number.  Which means that ucs-2 can no longer
represent the full unicode range, and therefore utf-16 was introduced.

This might help somewhat:
http://www.unicode.org/unicode/standard/principles.html

 Character encoding standards define not only the identity of each
 character and its numeric value, or code point, but also how this
 value is represented in bits.

 The Unicode Standard defines three encoding forms that allow the same
 data to be transmitted in a byte, word or double word oriented format
 (i.e. in 8, 16 or 32-bits per code unit). All three encoding forms
 encode the same common character repertoire and can be efficiently
 transformed into one another without loss of data.
[2]

cheers

[1] In utf-8, which is popular for network transmission, ascii
characters take one byte (with the top bit zero), Latin-1 characters
need two bytes, and other characters need two or more bytes.

[2] I dunno who convinced the Unicoders that 16 bits was a word and
32 a double word.  For me, 16 bits is a halfword, and a doubleword
would be 64 bits.  Ho hum.



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

Date: 6 Nov 2002 11:11:29 -0800
From: skendric@fhcrc.org (Stuart Kendrick)
Subject: Re: special characters in command-line
Message-Id: <62dbf7f1.0211061111.610c94a8@posting.google.com>

Hi John,

OK, I've spent the morning learning about swatch 'pipe' and Perl
STDIN.  So 'myprog' looks like this:

#!/usr/bin/perl -w
read STDIN, $line, 1000;
print "line = $line\n";
# parse $line and do things
 ...

For output, I get:
line =

i.e. line doesn't contain much (though it is defined).

I tried the following, too, with no change in output:

#!/usr/bin/perl -w
@lines = <STDIN>;
for $line (@lines) { print "line = $line\n }
# parse $line and do things
 ...

swatch.conf looks like this:

watchfor=/testing/
     pipe=/home/skendric/myprog $*

Soooo, is there something about acquiring STDIN that I don't
understand?  Or something about Perl's 'pipe' that I don't understand?

--sk

> > What other options might be available, for solving this issue?
> 
> 
> Instead of using
> 
>     exec command
> 
> in the swatch config file use
> 
>     pipe command
> 
> and read from STDIN so that characters aren't interpolated by the shell.
> 
> 
> 
> John


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

Date: 6 Nov 2002 11:16:39 -0800
From: skendric@fhcrc.org (Stuart Kendrick)
Subject: Re: special characters in command-line
Message-Id: <62dbf7f1.0211061116.69ff875f@posting.google.com>

Hi Walter,

In fact, I was incorrect. Swatch uses exec.

 ...
    my $sanitized_ = $_;
    @_ = split;

    # quote all special shell chars
    $sanitized_ =~ s/([;&\(\)\|\^><\$`'\\])/\\$1/g;
    my @sanitized_ = split(/\s+/, $sanitized_);

 ...

    exec_command('COMMAND' => "/home/skendric/myprog cns $sanitized_",
);

However, I'm not smart enough to figure out why the quoting of special
characters doesn't accomplish what I'm wanting.

--sk

roberson@ibd.nrc.ca (Walter Roberson) wrote in message news:<aq9nrf$cs8$1@canopus.cc.umanitoba.ca>...
> In article <62dbf7f1.0211051513.265bdbcc@posting.google.com>,
> Stuart Kendrick <skendric@fhcrc.org> wrote:
> :My program receives input from another process ("swatch"); the input
> :is a line from syslog.
>  
> :Basically, swatch performs a
> :"system ("/wherever/myprog Nov 5 13:53:12 process-name:  here is the
> :line from syslog");
>  
> :where 'myprog' is my Perl program.
> 
> If that's what swatch is doing, without doing an escaping, and if
> it's using system(), then swatch has a bug that needs to be fixed.
> swatch should be using  exec( programlocation, dataline )
> which would avoid any quoting problems.


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

Date: 6 Nov 2002 20:04:20 GMT
From: stan@temple.edu
Subject: Re: Unix command
Message-Id: <aqbsk4$2qn$1@cronkite.temple.edu>

ry@yokoyama.ws wrote:
> Thanks for people answering my question.  I did not konw perldoc.  I 
> will read it.

> I have another question. Is there FAQ?  If so, could you tell me where I 
> can find it.

Take a look at http://www.cpan.org/ for a extensive repository of
information for Perl programmers. A faq file is there too.



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

Date: Wed, 06 Nov 2002 20:10:51 GMT
From:  support@gethits22.com
Subject: Re: Unix command
Message-Id: <3DC9786D.5090301@gethits22.com>

http://www.perl.com/pub/q/FAQs

ry@yokoyama.ws wrote:
> Thanks for people answering my question.  I did not konw perldoc.  I 
> will read it.
> 
> I have another question. Is there FAQ?  If so, could you tell me where I 
> can find it.
> 
> Thanks   
> 
> In article <MPG.18330e03d4e586ff98968d@news-server.nyc.rr.com>, 
> ry@yokoyama.ws says...
> 
>>Hello All!
>>
>>Is it possible to invoke unix command from Perl?  If so, please tell me 
>>how. 
>>
>>Thanks in advance.
>>
>> 
>>
> 



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

Date: 06 Nov 2002 18:33:00 GMT
From: j.abromeit@jpberlin.de (Jens Abromeit)
Subject: Using SNMP::Multi Modul: putt responses to hash?!
Message-Id: <8$NwY2w2qwB@enerclim.jpberlin.de>


Hello together!

Actually I modify the example skript for SNMP::Multi . With some support from
friend & others (many thanks to Andreas & Hans!) I solved several problems,
but not all.


My aim:
----------

I will use the SNMP::Multi module from CPAN to get
SNMP status responses from similiar devices. From each device I will
compare two response values. Regarding to the result of the compare
process different messages should printed to a log. The description of SNMP
::Multi can be found at:

http://search.cpan.org/author/JOSHUA/SNMP-Multi-2.0/Multi.pm
--> Chapter Accessing SNMP Data from Agent Responses

SNMP::Multi uses the SNMP Modul.

The full modified script is added at the end of this posting

My problem:
------------------

I'm fairly new in using perl. After some discussions the following
solution suggestion to put the results per device in a hash with a key/value
pair of OID as keys and SNMP response values. Unfortuneately
I don't managed it to fill the %result_hash succesfully w

My request:
-----------------

I need some hint to see the "forest between the trees".
If some information about the script or modules is missing
please let me know.

Thank your for your help in advance.

Jens

PS: Working script will be posted, if wanted

-----------------------------script snippet--------------------------


54           }
55           my %result_hash = ();
56           for my $varlist ($result->varlists()) {
57             $result_hash{$_->name()} = $_->val();
             }
             if (($result_hash{'fbLink1.2'}==0) &&
                 ($result_hash{'fbLink2.2'}==0)) {
              print "$datum $host Konverter 1 shelf 1 totally down\n";

----------------------------full script below----------------------------


results to the following errormessage:

Can't call method "val" on an undefined value at ./06.pl line 57 (#1)  (F)
You used the syntax of a method call, but the slot filled by the  object
reference or package name contains an undefined value.  Something like  
this will reproduce the error:

        $BADREF = undef;
        process $BADREF 1,2,3;
        $BADREF->process(1,2,3);

Uncaught exception from user code:
Can't call method "val" on an undefined value at ./06.pl line 57.
---------------------------------------------------------------------------

As far as I see, at first a new empty hash

%result_hash

is created.(line 55).

This hash should be filled up with

$result_hash{$_->name()} = $_->val();  (line 57)

But the last code line causes the errormessage above:

"Can't call method "val" on an undefined value [...]"

As far as I see

{$_->name()} =

could be parsed successfully but not

$_->val() (see line 57 in script example)

Allthough both rely on $_, which has in this
case the SNMP::Varlist array. The SNMP::Varlist array
contains SNMP::Varbinds. The last offering the
methods ->val and ->name (see Modul SNMP below)


The full script:
----------------------

#!/usr/bin/perl

use strict;
use diagnostics;
use Carp;
use SNMP;
use SNMP::Multi;

chomp (my $datum =`date '+%d.%m.%Y %T'`);
my $verzeichnis = "/var/log";
my $logdatei = "log_ms";
my $permissions = 0777;
chdir $verzeichnis;
`touch $logdatei`;
chmod ($permissions, $logdatei);

        my $req = SNMP::Multi::VarReq->new (
        nonrepeaters => 2,
        hosts => [ qw/ 192.168.0.8/ ],
        vars  => [ [ '.1.3.6.1.4.1.3181.3.4.5.1.6.2' ], [ '.1.3.6.1.4.1.3181.3.4.5.1.8.2' ] ],
    );
    die "VarReq: $SNMP::Multi::VarReq::error\n" unless $req;

    my $sm = SNMP::Multi->new (
        Method      => 'get',
        MaxSessions => 32,
        PduPacking  => 16,
        Community   => 'public',
        Version     => '1',
        Timeout     => 5,
        Retries     => 3,
    )
    or die "$SNMP::Multi::error\n";

    $sm->request($req) or die $sm->error;
    my $resp = $sm->execute() or die "Execute: $SNMP::Multi::error\n";

chdir $verzeichnis;
open (STDOUT, "| tee -a $logdatei >/dev/ttyS0") or die "Fehler bei tee:$!\n";
for my $host ($resp->hosts()) {
print "$datum Server: $host:\n";
for my $result ($host->results()) {
           if ($result->error()) {
               print "Error with $host: ", $result->error(), "\n";
               next;
           }
           my %result_hash = ();
           for my $varlist ($result->varlists()) {
         $result_hash{$_->name()} = $_->val();
           }

    if (($result_hash{'fbLink1.2'}==0) && ($result_hash{'fbLink2.2'}==0)) {       =20
             print "$datum $host Konverter 1 shelf 1 totally down\n";
  }
 }


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

Date: 6 Nov 2002 11:29:30 -0800
From: emcee@inorbit.com (emcee)
Subject: Win32 and unicode
Message-Id: <4fac3c33.0211061129.5c1111e9@posting.google.com>

I am using ActivePerl on Windows 2000, XP, and 98, but whenever I use
a varible with a +, *, or \ (possibily other charactors) in a regex I
get an error. I read it has something to do with unicode support.
Since normally when I use a varible in a regex its from user input, a
file, or something from the internet, there is nothing I can do to
avoid these charactors in my varibles, the best I can do is replace
the charactors in the original text I was working with and put it back
when I am done. But this is alot of extra trouble and a waste of cpu
cycles, and not always feasable. I am curious if there is a way of
disabling unicode, preferably from my code. Thanks for any help.


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

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


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