[19321] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1516 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 06:06:09 2001

Date: Tue, 14 Aug 2001 03: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)
Message-Id: <997783511-v10-i1516@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 14 Aug 2001     Volume: 10 Number: 1516

Today's topics:
    Re: case sensitive (Tad McClellan)
    Re: Child env. variables <goldbb2@earthlink.net>
    Re: confused - can't print to file <krahnj@acm.org>
    Re: confused - can't print to file <dcsnospam@ntlworld.com>
    Re: Embedded perl question <goldbb2@earthlink.net>
        FAQ: How can I lock a file? <faq@denver.pm.org>
        Flock: Just to be sure ! (Mariman Center)
    Re: get rid of these leading zeros in Perl (David Combs)
    Re: get rid of these leading zeros in Perl <philippe.perrin@sxb.bsf.alcatel.fr>
    Re: How do I assing an entire array? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: MIME Type hash <bart.lateur@skynet.be>
    Re: Module installation problem <ronnie@r-davies.demon.co.uk>
    Re: perldoc is like Greek to a beginner?? (Pete Sohi)
        regex with ascii code - chr(0) ? <gbeymk@sgh.com.sg>
    Re: regex with ascii code - chr(0) ? <its_mr_impossible@hotmail.com>
    Re: regex with ascii code - chr(0) ? <krahnj@acm.org>
        shell error output grabbing <achatz@forthnet.gr>
    Re: shell error output grabbing <Tassilo.Parseval@post.rwth-aachen.de>
    Re: shell error output grabbing <Tassilo.Parseval@post.rwth-aachen.de>
    Re: shell error output grabbing <achatz@forthnet.gr>
    Re: shell error output grabbing <achatz@forthnet.gr>
    Re: shell error output grabbing <achatz@forthnet.gr>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 13 Aug 2001 23:19:52 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: case sensitive
Message-Id: <slrn9nh66o.7rt.tadmc@tadmc26.august.net>

jtjohnston <jtjohnston@courrier.usherb.ca> wrote:

>I want to find out if the user inputted, from html, the correct answer,
>but using case insensitive. 

>---------snip---------
>    $user_input = $in{'P2WC3Q4'};
>    $Return_Value = 0;
>    foreach $i (0..$#MyArray)
>    {
>       if (/$MyArray[$i]/i  eq  /$user_input/i)  #obviously not correct


   perldoc -f lc
   perldoc -f uc

There are also lcfirst and ucfirst functions.


You should let perl walk through the array for you. You seldom
need explicit indexing to walk an array in Perl:

   foreach my $element ( @MyArray ) {
      if ( lc($element) eq lc($user_input) ) {
      }
   }


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


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

Date: Tue, 14 Aug 2001 02:35:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Child env. variables
Message-Id: <3B78C6CF.F28E8C72@earthlink.net>

Shah Kashani wrote:
> 
> Hello,
> I have a perl program running an external shell-script using system();
> The external program sets environmental variables, but I cannot access
> them within the Perl program using $ENV. (Because the variables set in
> the child process are not set in the parent's)
> 
> Does anyone know how I can import these local variables set in the
> external script?

The answer is: don't do that.  system() is not the solution for this
problem.

I would suggest this:
my ($foo, $bar) = qx' . script; echo $FOO; echo $BAR ';
chomp( $foo, $bar );

Though you might want this:
foreach( qx[ . script; env ]  ) {
	chomp;
	(my ($key, $value) = split /=/, $_, 1) == 2 or next;
	# do stuff with $key, $value, like:
	# %childenv{$key} = $value;
}

Or:
my %childenv = map { chomp; /=/ ? ($`, $') : () } qx[ . script; env ];

I would advise against the "env" versions, since you can run into
trouble if any of the values have newlines in them.  Actually, you can
run into this trouble with the first method, too, but it's less of a
worry since you know what variables you're getting, and you can work to
avoid it.

Better yet, have the script itself print out the variables it's
producing, and capture them from there...  Or best, convert the shell
script to a perl script, and use do, or require, or make it into a
module -- that way, you have the data without a fork and exec, as needed
by system and qx.

-- 
The Swedish Chef has been assimilated. "Borg borg borg!"


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

Date: Tue, 14 Aug 2001 07:01:49 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: confused - can't print to file
Message-Id: <3B78CD80.367DCA0D@acm.org>

David Efflandt wrote:
> 
> On Sun, 12 Aug 2001 21:50:57 +0100, Terry <dcsnospam@ntlworld.com> wrote:
> > Hello again,
> >
> > I'll answer my own question as it may be of help to someone else :)
> > I assumed that truncating the file would set the filepointer at the start of
> > the truncated file. Apparently it doesn't because if I add
> >
> > seek (PROG, 0, 0);
> >
> > straight after the truncate statement then everything works fine :o)
> 
> It makes no sense to truncate at the end of file because the data before
> that in the file remains.  Seek the beginning _before_ you truncate.

Huh?

> The only reason your method worked was because the new data was longer
> than the old data, and the truncate was redundant.  But if data is unknown
> length (possibly shorter) you have to seek the beginning of the file, then
> truncate, or you may have old data lingering after the new shorter data.

What?

$ ls -l text.txt
-rw-r--r--    1 john     users       13870 Aug  3 13:21 text.txt
$ perl -e'open I,"+<text.txt";truncate I,0;seek I,0,0;print I "shorter
data\n"'
$ ls -l text.txt
-rw-r--r--    1 john     users          13 Aug 13 23:56 text.txt
$ cat text.txt
shorter data

Maybe you have a funny OS that doesn't allow this?



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 14 Aug 2001 10:05:30 +0100
From: "Terry" <dcsnospam@ntlworld.com>
Subject: Re: confused - can't print to file
Message-Id: <EO5e7.49062$e%3.7409740@news2-win.server.ntlworld.com>

"David Efflandt" <see-sig@from.invalid> wrote in message
news:slrn9nhcq8.nj2.see-sig@typhoon.xnet.com...
> On Sun, 12 Aug 2001 21:50:57 +0100, Terry <dcsnospam@ntlworld.com> wrote:
> > Hello again,
> >
> > I'll answer my own question as it may be of help to someone else :)
> > I assumed that truncating the file would set the filepointer at the
start of
> > the truncated file. Apparently it doesn't because if I add
> >
> > seek (PROG, 0, 0);
> >
> > straight after the truncate statement then everything works fine :o)
>
> It makes no sense to truncate at the end of file because the data before
> that in the file remains.  Seek the beginning _before_ you truncate.
>

-------------
Perlfunc Truncate

truncate FILEHANDLE,LENGTH
truncate EXPR,LENGTH

Truncates the file opened on FILEHANDLE, or named by EXPR, to the specified
length. Produces a fatal error if truncate isn't implemented on your system.
Returns true if successful, the undefined value otherwise.
-------------

IMHO the relevant part of the above is *to the specified length*. If you
specify length 0 then all data in the file is gone. It doesn't say that the
file is truncated from the current FI:LEHANDLE's position.

I could be wrong :)

Terry




> The only reason your method worked was because the new data was longer
> than the old data, and the truncate was redundant.  But if data is unknown
> length (possibly shorter) you have to seek the beginning of the file, then
> truncate, or you may have old data lingering after the new shorter data.
>
> --
> David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
> http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
> http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/




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

Date: Tue, 14 Aug 2001 03:16:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Embedded perl question
Message-Id: <3B78D068.DAEF0CD6@earthlink.net>

Robert J. Lee wrote:
> 
> Is there any easy way of saving the state of the perl interpretor to a
> file (i.e. the values of all variables AND any subroutines which have
> been processed)?
> 
> Basically, I've decided to use embedded perl to add scripting
> capabilities to a MUD I'm writing in C++, which has to be stopped and
> restarted periodically as code changes (needing recompiling). So,
> obviously, I need to save any changes to the perl bits as well.

Do you?  Wouldn't it be easier to have it so that "perl bit" are always
put into files, and then loaded via require?

> I've got as far as getting a hashtable of all data out of the stash,
> which should contain globs of all the data AFAICT. But the docs don't
> seem to give much explanation on what I should be doing with globs
> ("GV*"s) to turn them into data to save. (Also, I seem to be getting
> "SV*"s from the hash and I don't know how to turn them into "GV*"s).

This is the wrong way to do it, since it contains so much data, and you
don't really want to save *everything*.  If you need data saved, you can
use Data::Dumper or Storable.pm or whatever, but remember that you
should only save that which *needs* to be saved.

What are you adding scripting for?  I *hope* it's not so people can add
aliases for long commands... people can get special clients to do that,
and most serious mudders already have one, which they like -- they're
not garunteed to like whatever syntax you end up making up, and would
rather use the client they're used to.  Also, giving users scripting
ability is a real security hazard [even with Safe.pm].

Anyway, do you really expect that the perl code you had before a compile
will work well with everything after a recompile?  I don't think so.

Any bits of perl code you need should probably be put each in their own
file, and loaded from those files when the MUD starts [or better yet,
only when they're needed].  Saving the state that the loaded pieces of
code were in when the mud was last up is probably wrong.

-- 
The Swedish Chef has been assimilated. "Borg borg borg!"


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

Date: Tue, 14 Aug 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I lock a file?
Message-Id: <xn3e7.90$V3.170993152@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How can I lock a file?

    Perl's builtin flock() function (see the perlfunc manpage for details)
    will call flock(2) if that exists, fcntl(2) if it doesn't (on perl
    version 5.004 and later), and lockf(3) if neither of the two previous
    system calls exists. On some systems, it may even use a different form
    of native locking. Here are some gotchas with Perl's flock():

    1   Produces a fatal error if none of the three system calls (or their
        close equivalent) exists.

    2   lockf(3) does not provide shared locking, and requires that the
        filehandle be open for writing (or appending, or read/writing).

    3   Some versions of flock() can't lock files over a network (e.g. on
        NFS file systems), so you'd need to force the use of fcntl(2) when
        you build Perl. But even this is dubious at best. See the flock
        entry of the perlfunc manpage and the INSTALL file in the source
        distribution for information on building Perl to do this.

        Two potentially non-obvious but traditional flock semantics are that
        it waits indefinitely until the lock is granted, and that its locks
        are *merely advisory*. Such discretionary locks are more flexible,
        but offer fewer guarantees. This means that files locked with
        flock() may be modified by programs that do not also use flock().
        Cars that stop for red lights get on well with each other, but not
        with cars that don't stop for red lights. See the perlport manpage,
        your port's specific documentation, or your system-specific local
        manpages for details. It's best to assume traditional behavior if
        you're writing portable programs. (If you're not, you should as
        always feel perfectly free to write for your own system's
        idiosyncrasies (sometimes called "features"). Slavish adherence to
        portability concerns shouldn't get in the way of your getting your
        job done.)

        For more information on file locking, see also the section on "File
        Locking" in the perlopentut manpage if you have it (new for 5.6).

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           05.17
-- 
    This space intentionally left blank


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

Date: Tue, 14 Aug 2001 08:06:51 +0000 (UTC)
From: Mariman@mariman.net (Mariman Center)
Subject: Flock: Just to be sure !
Message-Id: <6412737777.20010813234629@mariman.net>


We  have  some  problems  in  a  script on a domain with high traffic,

Please correct me if I make mistakes here:


When I want the users to only READ in a file:

open (FILE, "$file");
flock (FILE,1);
#operations
close (FILE)

So, multiple users can access the file in reading, right ?


When I want one user to WRITE in a file
open (FILE, ">>$file"); # or open (FILE, ">$file");
flock (FILE,2);
#operations
close (FILE)

So, NO other user may write in this file til it isn't closed, right ?


Now,  what  happens if a file is flock (FILE,1) and that somebody else
tries to write into it, doing a flock (FILE,2) ? In other words, the 2
operations above, together by different users ?

Last, is it requested to write a flock (FILE,8), before closing it ?


Thanks for your help,

MC
--
Mariman Center
WebHosting - WebDesign
www.mariman.net



-- 
Posted from orion.besthost1.com [216.169.108.69] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: 14 Aug 2001 06:09:56 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <9lafbk$q1b$1@news.panix.com>

In article <3B7002CE.7DE7D802@sxb.bsf.alcatel.fr>,
Philippe PERRIN  <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
>Larry S wrote:
>> i want to print out a value of $id1, without leading zeros, so say
>> $id1 is "00061", i want to print it as "61".
>
>$id1 = "00061";
>print "$id1\n";    # will display 00061
>
>$id1 =~ s/^0*//g;
>print "$id1\n";    # will display 61
>

Is that /g really needed, and if so, why?

Thanks

David



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

Date: Tue, 14 Aug 2001 08:46:54 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <3B78C95E.11BBBC78@sxb.bsf.alcatel.fr>

David Combs wrote:
> >$id1 =~ s/^0*//g;
> >print "$id1\n";    # will display 61
> >
> 
> Is that /g really needed, and if so, why?

no it isn't... it's a mistake. since the ^0* already deletes all leading
zeros, there's no need to put a /g (global) option. just keep
$id1 =~ s/^0*//;

-- 
PhP

($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}


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

Date: Tue, 14 Aug 2001 09:55:55 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: How do I assing an entire array?
Message-Id: <3B78D98B.9060302@post.rwth-aachen.de>

Eric Bohlman wrote:
> Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> 
>>Stan Brown wrote:
>>
>>>Thaks, I thought of that, but what if @p_keys goes out of scope by the time
>>>I need it?
>>>
> 
>>Why should it do such a nasty thing? ;-)
>>
> 
>>Honestly, I can't quite follow you now. You certainly have to take care 
>>that you don't do something like this:
>>
> 
> Actually, it's a perfectly reasonable question for someone who's quite 
> familiar with programming in general, but less so with Perl, to ask.  

I just realized after Bart's reply that my response was not referring to 
the real question...as I wrote, I couldn't quite follow him. ;-)

In,
> for example, C, you'd get into a lot of trouble if you stashed a pointer 
> to a local variable into a data structure that was going to stick around 
> after you exited the current block; as soon as the local variable went out 
> of scope, your data structure would be pointing to an arbitrary place on 
> the stack.  Perl is somewhat unusual in that it makes the analogous 
> operations possible (by mapping variable names to SVs rather than directly 
> to the storage area; it's amazing just how much indirection can buy you).


When comparing C behaviour to Perl behaviour one should add that Perl 
has a distinctly more refined concept of scoping. Something like:

if (1) {
	my $n;
	for (1 .. 10) { $n++ }
}
if (1) {
	for (1 .. 10) { $n++ }
}

will fail to compile with strictures whereas in C you wouldn't even be 
allowed to create a new variable inside an if-block. So loosing the 
scope is easily 'achieved' in Perl.

I remember my first programms that I had written with the 
strict-pragma...it was hell. In first instance I always received a few 
hundred messages as for global symbols requiring explicit package names.


Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Tue, 14 Aug 2001 09:18:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: MIME Type hash
Message-Id: <6oqhntkhdh5arvc7c9uvmtasmbnh69kscc@4ax.com>

[The original post didn't appear on my server]

Ilmari Karonen wrote:

>In article <3B6FED28.6AD4952C@sxb.bsf.alcatel.fr>, Philippe PERRIN wrote:
>>
>>I need to know MIME types associated with file extensions, such as
>>'image/gif' for 'gif' or 'video/mpeg' for 'mpg'.... (see a good list at
>>http://www.utoronto.ca/ian/books/html4ed/appb/mimetype.html)
>>
>>I've started typing a hash to use with pattern matching... it works, but
>>I wonder if someone has already done it (quite long to type) ?
>
>If you're on a unix box, take a look at /etc/mime.types.  The Apache web
>server uses a similar file, but usually places it under /etc/httpd/conf/
>or some other Apache-specific directory.

In addition, check out the module LWP::MediaTypes. HTTP::Daemon, which
is part of the basic set on many distruibutions (it comes with libwww),
makes use of it.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 10:18:12 +0100
From: Ronnie Davies <ronnie@r-davies.demon.co.uk>
Subject: Re: Module installation problem
Message-Id: <EWXY2DAUzOe7EwlS@r-davies.demon.co.uk>

In article <997791157.969864@clover.origin.net.au>, Sisyphus
<kalinabears@hdc.com.au> writes
>
>
>
>This has always got rid of the 'unable to find....' error for me, and, as I
>said above, the other 2 don't matter, though I do have some notes on how to
>remove them which I'll post to you offlist.

By removing the 2>&1 string from mm_win32 and one from mm_unix, I have
made a makefile without any errors being thrown up.  However, I still
get the following output when running nmake:-

        c:\perl\bin\perl.exe -p -e "s/~DRIVER~/InterBase/g" <
C:/Perl/site/lib/a
uto/DBI/Driver.xst > InterBase.xsi
File not found
        c:\perl\bin\perl.exe -IC:\Perl\lib -IC:\Perl\lib
C:\Perl\lib\ExtUtils/xs
ubpp   -typemap C:\Perl\lib\ExtUtils\typemap InterBase.xs > InterBase.c
Cannot open 'InterBase.xsi': No such file or directory in InterBase.xs,
line 19
NMAKE : fatal error U1077: 'C:\PERL\BIN\PERL.EXE' : return code '0x1'
Stop.

How do I get nmake to work without errors?

Thanks in advance
-- 
Ronnie Davies

He who laughs last........thinks slowest!


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

Date: 14 Aug 2001 02:58:23 -0700
From: amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <1ab8c4be.0108140158.7c7f9564@posting.google.com>

Viva Carlos!

Bravo! Halleluyah and well done! 

The Perl doc might as well be written in Chinese to those who are
unfamiliar with Perl and its foundations. It makes a terrible learning
aid and is a abbreviated hyperlinked pages which are meaningless to
the novice. Without a hint or pointer to begin with, it is more than
easy to get lost search the Perl doc for hours and find nothing of
use.

Can someone recommend other APIs, documentation, references guides,
links, user-groups, tutorials that might be better pitched for those
still on the learning curve?.....

Thank you very much. (And thank heavens I am not alone in my
difficulties in getting to grips with the Perl doc).

Cheers.

Pete.



Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote in message news:<MPG.15da6ff931aa281d989716@news.edmonton.telusplanet.net>...
> Hi everyone, 
> 
> A lot of the perldoc documentation is very thorough and people have 
> graciously put a lot of time into it.  For this I am grateful but a lot 
> of it for someone like me who is a beginner is like Greek.  
> Interpolation, unary operator, lexical scope, expected semantics, extent 
> of a string...  These are just some of the "Greek" terms in perldoc 
> perlop that I saw.  Now I have some idea of what some of these are but 
> the point I am making is that it seems to me that another version of the 
> documentation needs to be rewritten in common English.  Without so much 
> computereese in it.  Especially for us new beginners.  
> 
> It is very frustrating sometimes to be told to go read this or that perl 
> documentation only to go to the documentation and to find myself reading 
> something that has a bunch of terms that I don't even understand.  I need 
> a simple answer to a simple and pointed question and I end up being 
> confronted with a volume of information which ends up throwing terms at 
> me that are even more confusing.  
> 
> Please don't get me wrong.  It's good to read through the documentation 
> and I appreciate every tid bit and insight that is given me on this 
> newsgroup and every suggestion as to which docomentation I should read.  
> I truly do.  But I guess I am just wondering if it might not be good to 
> have a new perldoc added devoted to giving the common meaning to as many 
> computereese terms as can be found?
> 
> I don't mean to step on anyone's toes.  I am just expressing my 
> frustrations as a beginner to Perl for what they are worth and welcome 
> any feedback on any of this. 
> 
> Thanks.


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

Date: Tue, 14 Aug 2001 16:50:30 +0800
From: YMK <gbeymk@sgh.com.sg>
Subject: regex with ascii code - chr(0) ?
Message-Id: <3B78E656.21D3B4EF@sgh.com.sg>

I have a field which allow pressing <Enter> key within it !
When I take a look on it, I see "...^@   ...", i.e. whenever a <Enter>
is pressed, 
it will shown as ^@ follow by 4 spaces.

^@ is a single character (as in vi), when I read it (i.e. substr), that
give chr(0)!

I am trying to get rid of ^@ with s/chr(0)//, but it did not work !
How should I do it ?


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

Date: Tue, 14 Aug 2001 09:55:43 +0100
From: "John Taylor" <its_mr_impossible@hotmail.com>
Subject: Re: regex with ascii code - chr(0) ?
Message-Id: <997779424.13025.0.nnrp-10.c2de1f0e@news.demon.co.uk>

Hi,

If its definately a chr(0). Try this:

$theChar = sprintf("%c", 0); # 0 being the character code in question. This
can be changed to any ASCII code.
$inputField =~ s/$theChar//;


HTH,

John Taylor.


"YMK" <gbeymk@sgh.com.sg> wrote in message
news:3B78E656.21D3B4EF@sgh.com.sg...
> I have a field which allow pressing <Enter> key within it !
> When I take a look on it, I see "...^@   ...", i.e. whenever a <Enter>
> is pressed,
> it will shown as ^@ follow by 4 spaces.
>
> ^@ is a single character (as in vi), when I read it (i.e. substr), that
> give chr(0)!
>
> I am trying to get rid of ^@ with s/chr(0)//, but it did not work !
> How should I do it ?




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

Date: Tue, 14 Aug 2001 09:04:49 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex with ascii code - chr(0) ?
Message-Id: <3B78EA55.C832BF4B@acm.org>

YMK wrote:
> 
> I have a field which allow pressing <Enter> key within it !
> When I take a look on it, I see "...^@   ...", i.e. whenever a <Enter>
> is pressed,
> it will shown as ^@ follow by 4 spaces.
> 
> ^@ is a single character (as in vi), when I read it (i.e. substr), that
> give chr(0)!
> 
> I am trying to get rid of ^@ with s/chr(0)//, but it did not work !
> How should I do it ?

s/\0//;

Or if you have more than one.

tr/\0//d;



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 14 Aug 2001 10:39:16 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: shell error output grabbing
Message-Id: <3B78D5A4.242AADCD@forthnet.gr>

Just a very simple question:

From perl:

system "snmpwalk $router $community > $interfaces_file";

From unix shell::

$ snmpwalk router community > /tmp/interfaces.tmp
Timeout: No Response from router

Is there a way i can grab this error output into a perl var?

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: Tue, 14 Aug 2001 10:06:06 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: shell error output grabbing
Message-Id: <3B78DBEE.5070205@post.rwth-aachen.de>

Tassos Chatzithomaoglou wrote:
> Just a very simple question:
> 
> From perl:
> 
> system "snmpwalk $router $community > $interfaces_file";
> 
> From unix shell::
> 
> $ snmpwalk router community > /tmp/interfaces.tmp
> Timeout: No Response from router
> 
> Is there a way i can grab this error output into a perl var?
> 
> 

Yes, there is. Open STDERR and redirect to a file before invoking 
system. Of course, this assumes that the above message is written to 
stderr which is probably the case:

ooen SDTERR, ">snmpwalk.err" or die "Error: Could not redirect: $!";
my $error = system "snmpwalk $router $community > $interface_file";
close STDERR;

Mark that the system-statement above does not capture the output into 
$error but rather the return value. Name it thus since 0 is usually 
returned on success so you could write:
if (not $error) { do something on success }

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Tue, 14 Aug 2001 10:07:27 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: shell error output grabbing
Message-Id: <3B78DC3F.9040705@post.rwth-aachen.de>

Tassilo von Parseval wrote:

> Yes, there is. Open STDERR and redirect to a file before invoking 
> system. Of course, this assumes that the above message is written to 
> stderr which is probably the case:
> 
> ooen SDTERR, ">snmpwalk.err" or die "Error: Could not redirect: $!";
   ^^^^

Ummh, open of course.

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Tue, 14 Aug 2001 11:40:12 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
To: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: Re: shell error output grabbing
Message-Id: <3B78E3EC.2D406CB4@forthnet.gr>

Strangely 

system "snmpwalk $router $community >$interfaces_file 2>$interfaces_error"

did the job, although error output is stored in a file, but that's not a problem.


Tassos Chatzithomaoglou wrote:
> 
> Just a very simple question:
> 
> From perl:
> 
> system "snmpwalk $router $community > $interfaces_file";
> 
> From unix shell::
> 
> $ snmpwalk router community > /tmp/interfaces.tmp
> Timeout: No Response from router
> 
> Is there a way i can grab this error output into a perl var?
> 
> --
> ***************************
> Chatzithomaoglou Anastasios
>  Network Operations Center
>        FORTHnet S.A.
>    <achatz@forthnet.gr>
> ***************************

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: Tue, 14 Aug 2001 11:40:16 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
To: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: Re: shell error output grabbing
Message-Id: <3B78E3F0.D47CCB2B@forthnet.gr>

Strangely 

system "snmpwalk $router $community >$interfaces_file 2>$interfaces_error"

did the job, although error output is stored in a file, but that's not a problem.


Tassos Chatzithomaoglou wrote:
> 
> Just a very simple question:
> 
> From perl:
> 
> system "snmpwalk $router $community > $interfaces_file";
> 
> From unix shell::
> 
> $ snmpwalk router community > /tmp/interfaces.tmp
> Timeout: No Response from router
> 
> Is there a way i can grab this error output into a perl var?
> 
> --
> ***************************
> Chatzithomaoglou Anastasios
>  Network Operations Center
>        FORTHnet S.A.
>    <achatz@forthnet.gr>
> ***************************

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

Date: Tue, 14 Aug 2001 11:40:14 +0300
From: Tassos Chatzithomaoglou <achatz@forthnet.gr>
To: Tassos Chatzithomaoglou <achatz@forthnet.gr>
Subject: Re: shell error output grabbing
Message-Id: <3B78E3EE.8BD5D278@forthnet.gr>

Strangely 

system "snmpwalk $router $community >$interfaces_file 2>$interfaces_error"

did the job, although error output is stored in a file, but that's not a problem.


Tassos Chatzithomaoglou wrote:
> 
> Just a very simple question:
> 
> From perl:
> 
> system "snmpwalk $router $community > $interfaces_file";
> 
> From unix shell::
> 
> $ snmpwalk router community > /tmp/interfaces.tmp
> Timeout: No Response from router
> 
> Is there a way i can grab this error output into a perl var?
> 
> --
> ***************************
> Chatzithomaoglou Anastasios
>  Network Operations Center
>        FORTHnet S.A.
>    <achatz@forthnet.gr>
> ***************************

-- 
***************************
Chatzithomaoglou Anastasios
 Network Operations Center
       FORTHnet S.A.
   <achatz@forthnet.gr>
***************************


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

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


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