[19979] in Perl-Users-Digest
Perl-Users Digest, Issue: 2174 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 21 14:10:57 2001
Date: Wed, 21 Nov 2001 11:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006369813-v10-i2174@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 21 Nov 2001 Volume: 10 Number: 2174
Today's topics:
How to not get space between fields (phil)
Re: How to not get space between fields (Tad McClellan)
Re: How to not get space between fields <wolfram.pfeiffer@bigfoot.com>
Re: How to not get space between fields <Tassilo.Parseval@post.rwth-aachen.de>
Re: How to split variable length row <5l259r001@sneakemail.com>
I would like to call the perl from java <DOBLEJ@teleline.es>
Re: I would like to call the perl from java <bernard.el-hagin@lido-tech.net>
Re: need help with a seemingly simple regex <bart.lateur@skynet.be>
Re: need help with a seemingly simple regex <5l259r001@sneakemail.com>
Newbie question <mjc@drizzle.net>
Re: Newbie question <Laocoon@eudoramail.com>
Re: result pages (10 by 10) <newsgroup_mike@ultrafusion.co.uk>
Re: slicing multi dimensional arrays <5l259r001@sneakemail.com>
SNMP:: Session, SNMP::Varbind (Anand Ramamurthy)
Re: using sendmail from perl (Wiliam Stephens)
win32::ole - change excel worksheet name (Bobby Ray)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Nov 2001 09:27:43 -0800
From: wanttorun100@altavista.com (phil)
Subject: How to not get space between fields
Message-Id: <14342399.0111210927.4e69c15@posting.google.com>
I need to create a fixed field file like
IL61526
GA42568
CA90102
I've come up with
printf("%-02s",$state) ;
printf("%-09s \n",$zip) ;
that prints
IL 61526
GA 42568
CA 90102
Is there a way to print w/o the space between fields?
------------------------------
Date: Wed, 21 Nov 2001 17:59:32 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to not get space between fields
Message-Id: <slrn9vno67.ofi.tadmc@tadmc26.august.net>
phil <wanttorun100@altavista.com> wrote:
>I need to create a fixed field file like
>
>IL61526
>GA42568
>CA90102
>
>I've come up with
>
> printf("%-02s",$state) ;
> printf("%-09s \n",$zip) ;
>
>that prints
>
>IL 61526
>GA 42568
>CA 90102
>
>Is there a way to print w/o the space between fields?
Did you really expect us to be able to understand the output
without showing the values of $state and $zip? If so, you
have an unreasonable expectation :-)
You must have a space at the beginning of $zip or at the end
of $state. ie. your data is broken, not your code.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Nov 2001 18:00:06 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: How to not get space between fields
Message-Id: <9tgq36$2nc$1@news.rz.uni-karlsruhe.de>
phil <wanttorun100@altavista.com> wrote:
> I need to create a fixed field file like
> IL61526 [...]
> I've come up with
> printf("%-02s",$state) ;
> printf("%-09s \n",$zip) ;
> that prints
> IL 61526 [...]
> Is there a way to print w/o the space between fields?
When I tested the code, it printed the values *whithout* the space.
Your $state or $zip variable probably contain the space, you might want
to strip it from them. You can also set a maximum field width in printf
(currently, you only set a *minimum* field width). Have a look at the
sprintf entry in the perlfunc helppage for information about setting a
maximum field width.
Gruss,
Wolfram
--
Again, I blaim the great unwashed and their unwillingness or non-ability
to grasp any concept beyond eat, sleep, piss, shit, and shag.
-- Justin Moe, SDM
------------------------------
Date: Wed, 21 Nov 2001 19:00:32 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: How to not get space between fields
Message-Id: <9tgq40$aqr$00$1@news.t-online.com>
On 21 Nov 2001 09:27:43 -0800, phil wrote:
> I need to create a fixed field file like
>
> IL61526
> GA42568
> CA90102
>
> I've come up with
>
> printf("%-02s",$state) ;
> printf("%-09s \n",$zip) ;
>
> that prints
>
> IL 61526
> GA 42568
> CA 90102
I don't quite understand. This prints something different for me. But does
the following suit your needs?
ethan@ethan:~$ perl
$state = "ILLINOIS";
$zip = "90102";
printf "%2.2s%s\n", $state, $zip;
__END__
IL90102
> Is there a way to print w/o the space between fields?
This is in general quite easy. (s)printf takes as first argument a
format string, see in the example. Hence
printf "%s%s%s", $string1, $string2, $string3;
would put the three strings immediately one after another.
Tassilo
--
A person with one watch knows what time it is; a person with two watches is
never sure. Proverb
------------------------------
Date: Wed, 21 Nov 2001 17:52:11 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: How to split variable length row
Message-Id: <9tgq8f$287$05$3@news.t-online.com>
"John Smith" <nospam@newsranger.com> schrieb im Newsbeitrag
news:UtPK7.32928$xS6.56092@www.newsranger.com...
| Thank you guys for the solution.
| I have to learn a lot.
A simple rule of thumb would be:
If you have a simple assumption like "Doing xyz like *this* will work" (or
vice versa), test it (especially before posting it to a newsgroup).
Never expect Perl to behave a certain way. Perl will surprise you many times
with useful but unexpected results because in Perl, *magic* does exist (and
I am not joking).
But sometimes you can really think of Perl as a thick-headed Camel.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Fri, 16 Nov 2001 00:13:42 GMT
From: JOSE <DOBLEJ@teleline.es>
Subject: I would like to call the perl from java
Message-Id: <3BF45D4D.79478B1D@teleline.es>
Hi all:
I would like to call the perl function from java.
How?
Thanks in advanced.
------------------------------
Date: 21 Nov 2001 16:55:59 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: I would like to call the perl from java
Message-Id: <slrn9vnq3s.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 16 Nov 2001 00:13:42 GMT, JOSE <DOBLEJ@teleline.es> wrote:
>
> Hi all:
>
> I would like to call the perl function from java.
> How?
Even if there *were* such a thing as "the perl function", and there
isn't, this would be a question for a Java forum, not a Perl forum.
Cheers,
Bernard
------------------------------
Date: Wed, 21 Nov 2001 16:40:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: need help with a seemingly simple regex
Message-Id: <d7mnvtsdqh7st3av8i7g60m3n9tbb33cpc@4ax.com>
Ciaran McCreesh wrote:
>Godzilla! wrote:
>> print "Content-type: text/plain\n\n";
>
>Oh dear... Shurely some mishtake? That would be \r\n\r\n , no?
Not in CGI. The server has to translate these to the proper line endings
for the network, when sending the response to the browser.
--
Bart.
------------------------------
Date: Wed, 21 Nov 2001 17:55:47 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: need help with a seemingly simple regex
Message-Id: <9tgq8g$287$05$4@news.t-online.com>
"pt" <mnemotronic@mind\no-spam/spring.com> schrieb im Newsbeitrag
news:3BFB1CAE.C6A46BDA@mindspring.com...
|
|
| Travis Spencer wrote:
|
| > Hello,
| >
| > I am stuck on a regular expression that seems as though it should be
pretty easy, but I can't seem
| > to get it.
| >
| > I am trying to search for all JPG files used in a certain Web page. The
img elements looks like
| > this:
| >
| > <img src="images/large/0010.jpg">
| > <img src="images/large/0102.jpg">
| > <img src="images/large/0215.jpg">
| > etc.
| >
| > But the problem is that there are many referenced to JPGs that are
prefixed with the string "tn_" in
| > the same page. For instance:
| >
| > <img src="images/tn/tn_0010.jpg">
| > <img src="images/tn/tn_0102.jpg">
| > <img src="images/tn/tn_0215.jpg">
| >
| > This is what I have tried so far, but the negation doesn't help at all.
| >
| > [^tn_[0-9]+.jpg)][0-9]+.jpg
| >
|
| Do you want just the filename, the full path, the filename plus
extension?
|
| Here's something that will give just the filename part, and how I
arrived at it :
| Search for "<IMG"
| followed by 1 or more whitespace
| followed by "SRC"
| followed by 0 or more whitespace
| followed by "="
| followed by 0 or more whitespace
| followed by 1 or more of any char
| followed by "/" or "\" (if delim is always "/" drop "\")
| followed by 1 or more anything that isn't "." (CAPTURE)
| followed by ".JPG"
| make it case insensitive so that we can use "IMG" and "SRC"
| in the regexp to distinguish those chars from stuff like "\s"
|
| /<IMG\s+SRC\s*=\s*.*\/|\\([^.]+)\.JPG/i
|
| Most of the work is in differentiating image tags from something else
that might have a
| 'src="file/blah/blah/'. This might be more safety than is needed, and
there's probably a module that
| will parse HTML files for you, but re-inventing the wheel *CAN* be a good
exercise.
And a dangerous one.
Try to match
<img alt="wefwefw" src="sdffsd">
using you regex.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Wed, 21 Nov 2001 10:06:21 -0800
From: mike <mjc@drizzle.net>
Subject: Newbie question
Message-Id: <s6rnvt0rm7sdh0rai6mgb9c4m6uh58fvtm@4ax.com>
Is there a user group someplace that will look at newbie
code and make suggestions for shortcuts or improvements?
Mike
------------------------------
Date: Wed, 21 Nov 2001 19:07:34 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Newbie question
Message-Id: <Xns9160C299ECBALaocooneudoramailcom@62.153.159.134>
hmmm.. maybe this one?
------------------------------
Date: Wed, 21 Nov 2001 16:35:01 GMT
From: "Mike Mackay [Ultrafusion]" <newsgroup_mike@ultrafusion.co.uk>
Subject: Re: result pages (10 by 10)
Message-Id: <VIQK7.13823$%j6.1412423@news1.cableinet.net>
I found this webpage and I think it might help you a little. Lots of
explanation to it.
http://tlc.perlarchive.com/articles/perl/dm0001.shtml
Regards,
Mike Mackay.
------------------------------
Date: Wed, 21 Nov 2001 17:41:00 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: slicing multi dimensional arrays
Message-Id: <9tgq89$287$05$1@news.t-online.com>
"Abe Timmerman" <abe@ztreet.demon.nl> schrieb im Newsbeitrag
news:pb9nvt045okh0o3cvbaforouakdf1dap10@4ax.com...
[...]
| This is basically the same as Martiens solution, but shorter.
|
| sub multi_dim_slice {
|
| my( $orig, $start, $size ) = @_;
|
| die "Sizes don't match." unless @$orig == @$start && @$start ==
@$size;
|
| return map [
| @{ $orig->[$_] }[ $start->[$_] .. ($start->[$_] + $size->[$_] -
1) ]
| ] => 0 .. $#{ $start };
|
| }
Thanks, Abe.
I posted the solution I'm using now as a follow-up to Anno's post. As Anno
rightfully guessed (and it's my fault that he and Martien had to guess), the
sub needs recursion.
Best regards,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: 21 Nov 2001 10:45:32 -0800
From: anand_ramamurthy@yahoo.com (Anand Ramamurthy)
Subject: SNMP:: Session, SNMP::Varbind
Message-Id: <761041e6.0111211045.5b580fcb@posting.google.com>
I am trying to run the following script (an example I found
on comp.lang.perl.misc:
use SNMP 1.8;
my $host = shift || localhost;
my $comm = shift || public;
$sess = new SNMP::Session(DestHost => $host, Community => $comm);
$var = new SNMP::Varbind([]);
do {
$val = $sess->getnext($var);
print "$var->[$SNMP::Varbind::tag_f].$var->[$SNMP::Varbind::iid_f] = ",
"$var->[$SNMP::Varbind::val_f]\n";
} until ($sess->{ErrorStr});
I downloaded Net-SNMP-4.0.0.tar.gz from CPAN and installed SNMP.
1. I get the error:
SNMP does not define $SNMP::VERSION- version check failed .....
If I change use SNMP 1.8; to use Net::SNMP
I get following error:
Can't locate object method "new" via package "SNMP:Session" (perhaps
you forgot to load "SNMP::Session").
Am I missing anything from the Net::SNMP installation or
something wrong withe script.
All I am doing in my script is to do a snmpwalk to make sure that
I can reach the device (an alternate to ping).
Thank you
------------------------------
Date: 21 Nov 2001 09:03:35 -0800
From: wil@fbagroup.co.uk (Wiliam Stephens)
Subject: Re: using sendmail from perl
Message-Id: <39e3e00a.0111210903.7417f41d@posting.google.com>
Philip Newton <pne-news-20011121@newton.digitalspace.net> wrote in message news:<1u0nvt0hm7mhmpsfsel0ciic142u8ee8k7@4ax.com>...
> On 21 Nov 2001 01:37:23 -0800, wil@fbagroup.co.uk (Wiliam Stephens)
> wrote:
>
> > Try the following regex:
> >
> > $_ =~ /[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ |\t|\r|\n]*/;
>
> Why do you want to match 'any of (space, pipe, tab, pipe, CR, pipe, NL)'
> a couple of times there? And what's the two [^ <>\t] right nexto to one
> another for? And shouldn't the @ have a \ in front of it? And what are
> the \ in front of the " for? And what are the ( ) parentheses for?
> They're in a rather strange place. And you seem to allow any character
> at all in a domain name (except for space, tab, less-than, and
> greater-than).
>
> All that leads me to distrust the regex at first sight.
if ($mail =~/ /)
{ error_sub... }
if ($mail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
$mail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{ error_sub... }
How about that one ?
Wil
------------------------------
Date: 21 Nov 2001 11:01:44 -0800
From: bobby@nationalgoat.com (Bobby Ray)
Subject: win32::ole - change excel worksheet name
Message-Id: <699478d4.0111211101.30b7c5a@posting.google.com>
How do I rename an Excel worksheet?
I trim blanks from the name, and would like to
rename sheet with neat name.
my $count = $Book->Worksheets->Count;
my @Sheets; # the names of the last four sheets in the workbook
for my $current (0..3)
{
$Sheets[$current] =
trim( $Book->Worksheets($count - $current)->Name );
$Book->Worksheets($count - $current)->Name = $Sheets[$current];
}
Here's the message I get:
Can't modify non-lvalue subroutine call at excel.pl line 33.
Thanks,
Bobby
------------------------------
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 2174
***************************************