[22509] in Perl-Users-Digest
Perl-Users Digest, Issue: 4730 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 19 14:06:00 2003
Date: Wed, 19 Mar 2003 11:05:09 -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, 19 Mar 2003 Volume: 10 Number: 4730
Today's topics:
Re: Adding Perl library to default OS X Server install <sbour@niaid.nih.gov>
ANNOUNCE: Physics::Unit Version 0.02 (Christopher Maloney)
ANNOUNCE: Net::NIS 0.34 <esm@nospam.pobox.com>
Re: Anyone For Golf? (Resistor Colour Codes) (Jasper)
Re: Anyone For Golf? (Resistor Colour Codes) (Anno Siegel)
Re: Anyone For Golf? (Resistor Colour Codes) <barbr-en@online.no>
Re: Array reference argument to subroutine problem <barryk2@SPAM-KILLER.mts.net>
Re: Array reference argument to subroutine problem <mjcarman@mchsi.com>
Re: Cannot get authenticated to Yahoo's SMTP servers wh <aknntp@yahoo.com>
Date Calculation (Dan Rabb)
Re: Date Calculation <tore@aursand.no>
Re: Date Calculation <ethan@draupnir.gso.saic.com>
Re: Expression with varying number of conditions <Joly.Patrick@ic.gc.ca>
Re: more efficent way to foreach ... $x.=$_ <barryk2@SPAM-KILLER.mts.net>
Re: perl ssh background process <vladimir@NoSpamPLZ.net>
Re: perl-ldap problem (Alessandro Favretto)
Problem in conversion letter <shlomit@stam.com>
Re: Problem in conversion letter <cbk047@email.mot.com>
Re: Question about PERL modules EXPECT/Net::Telnet <vladimir@NoSpamPLZ.net>
randomly curropted data <shlomit@stam.com>
running a script on multiple files in a directory <ahmad@dcs.qmul.ac.uk>
Re: running a script on multiple files in a directory <alex@alexbanks.com>
Re: running a script on multiple files in a directory <aknntp@yahoo.com>
Re: running a script on multiple files in a directory <tore@aursand.no>
Re: running a script on multiple files in a directory (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Mar 2003 09:07:22 -0500
From: Stephan Bour <sbour@niaid.nih.gov>
Subject: Re: Adding Perl library to default OS X Server install
Message-Id: <BA9DE3CA.63F6%sbour@niaid.nih.gov>
in article BA9DDE25.63F3%sbour@niaid.nih.gov, Stephan Bour at
sbour@niaid.nih.gov wrote on 3/19/03 08:43:
> in article 1fs222m.2f0h2n1kmk0nyN%tony@svanstrom.com, Tony L. Svanstrom at
> tony@svanstrom.com wrote on 3/19/03 00:34:
>
>> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>
>>> perl.h is part of a standard Perl installation. Under 10.1.5 it's under
>>> /Library/Perl/darwin/CORE/perl.h, though that may have changed.
>>
>> 10.2.4 (non-server, as if that should matter in this case):
>>
>> /System/Library/Perl/darwin/auto/Apache/include/modules/perl/mod_perl.h
>> /System/Library/Perl/darwin/CORE/perl.h
>>
>
> Yes, that's how it is under OS 10.2.4 "client". However, the Server version
> doesn't have this lib. As a matter of fact, the ONLY lib in the CORE
> directory is libperl.dylib in OS X Server. I'm just wondering whether this
> is by design or whether something bad happened during my own installation.
> If anybody is running OS X Server 10.2 or later would you let me know
> whether you have the standard libs in the CORE directory?
>
> Thank you.
>
Got it. All I needed was install the Dev Tools.
------------------------------
Date: Wed, 19 Mar 2003 18:08:43 GMT
From: dude@chrismaloney.com (Christopher Maloney)
Subject: ANNOUNCE: Physics::Unit Version 0.02
Message-Id: <9d545fca445b1a0c2d81debff19c98bf@news.teranews.com>
Manipulate physics units and dimensions.
See http://search.cpan.org/author/KLORTHO/
Enjoy!
------------------------------
Date: Wed, 19 Mar 2003 18:08:42 GMT
From: Eduardo Santiago <esm@nospam.pobox.com>
Subject: ANNOUNCE: Net::NIS 0.34
Message-Id: <36911fe1efae6edcfa11f710294dc343@news.teranews.com>
Net::NIS 0.34 has been uploaded to CPAN:
file: $CPAN/authors/id/E/ES/ESM/Net-NIS-0.34.tar.gz
size: 16124 bytes
md5: 30e5847227fdd999c3c815563fbbe6fc
This is a low-priority bug fix release.
Changes since 0.33
------------------
* https://rt.cpan.org/NoAuth/Bug.html?id=1865
tweak the test suite so they pass if map keys have spaces (ick).
* Compile and run properly on Perl 5.8.0 with ithreads & 64bit ints
Thanks to Peter Eriksson <peter at ifm dot liu dot se> for patch.
What Is It?
-----------
Net::NIS provides simple, Perl-style access to NIS (formerly YP) maps:
use Net::NIS;
tie %ip, 'Net::NIS', 'hosts.byname'
or die "Cannot tie to hosts.byname YP map: $yperr\n";
$hostname = "test";
print "$hostname's IP address is ", $ip{$hostname} || "<unknown>", "\n";
--
Ed Santiago Toolsmith esm@pobox.com
------------------------------
Date: 19 Mar 2003 06:26:42 -0800
From: jasper@mccrea.demon.co.uk (Jasper)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <b6891527.0303190626.6b4204c7@posting.google.com>
tiltonj@erols.com (Jay Tilton) wrote in message news:<3e7825b9.49239512@news.erols.com>...
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> : Jasper <jasper@mccrea.demon.co.uk> wrote in comp.lang.perl.misc:
> : > #!perl -l
> : > print map{.5*index acowdzanlleeueoleyit,/..(..?)/&&$1}@ARGV
> : >
> : > think this is around 62
> :
> : None of your solutions interprets the third ring as so many zeroes.
> :
> : Under Perl 5.8.0, sprintf can do this at little letter cost:
> :
> : printf "%d%d%0*d", @three_numbers, 0;
> :
> : The third of @three_numbers gives the number of trailing zeroes. Except
> : when the third ring is black, when it prints a zero it shouldn't. I'm
> : not that familiar with color code, but by Murphy the third ring *can*
> : be black.
>
> Murphy's got your number. Reistors smaller than 100 ohms do exist.
>
> The best I can do with it, bringing in a clue from Benjamin, adds a
> lot of characters and looks decidedly anti-golfish. A change of
> Jasper's very slick technique shaves two strokes inside the map block.
>
> #!perl
> print 0+sprintf"%d%de%d\n",map{/..(..?)/;
> acowdzanlleeueoleyit=~$1;"@-"/2}@ARGV
As a matter of interest, why does:
index acowdzanlleeueoleyit, /..(..?)/
not work? It seems to me like the match should pass the relevant bit
to index in array context. But it doesn't.
Jasper
------------------------------
Date: 19 Mar 2003 14:45:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <b59vr1$obb$3@mamenchi.zrz.TU-Berlin.DE>
Jasper <jasper@mccrea.demon.co.uk> wrote in comp.lang.perl.misc:
> As a matter of interest, why does:
>
> index acowdzanlleeueoleyit, /..(..?)/
>
> not work? It seems to me like the match should pass the relevant bit
> to index in array context. But it doesn't.
Because there is no list context. The arguments of index are
three scalars. "index( "acowdzanlleeueoleyit", (/..(..?)/)[ 0])"
works as intended.
Anno
------------------------------
Date: Wed, 19 Mar 2003 18:55:06 +0100
From: Kåre Olai Lindbach <barbr-en@online.no>
Subject: Re: Anyone For Golf? (Resistor Colour Codes)
Message-Id: <cpah7vkinhh48i28a3b79t81a4r39ghjck@4ax.com>
On Wed, 19 Mar 2003 08:15:23 GMT, tiltonj@erols.com (Jay Tilton)
wrote:
>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
>: Jasper <jasper@mccrea.demon.co.uk> wrote in comp.lang.perl.misc:
>: > #!perl -l
>: > print map{.5*index acowdzanlleeueoleyit,/..(..?)/&&$1}@ARGV
>: >
>: > think this is around 62
>:
>: None of your solutions interprets the third ring as so many zeroes.
>:
>: Under Perl 5.8.0, sprintf can do this at little letter cost:
>:
>: printf "%d%d%0*d", @three_numbers, 0;
>:
>: The third of @three_numbers gives the number of trailing zeroes. Except
>: when the third ring is black, when it prints a zero it shouldn't. I'm
>: not that familiar with color code, but by Murphy the third ring *can*
>: be black.
>
>Murphy's got your number. Reistors smaller than 100 ohms do exist.
The third ring might even be a colour different from those stated, to
indicate a value less than 10 Ohm, and even less than 1 Ohm.
Third ring indicates 10En, where n is the same number from the
colour-range as mentioned elsewhere in this thread, pluss silver, gold
and others (if I remember right! And I am NOT talking about the
precision ring here, which is ring 4) These extra colours indicate a
negative value of n.
(The nicest value is black-black-black, which is a zero-ohm, often
used as a connector-bridge in automated soldering :)
There is also a five ring system, with even more values and better
precision.
--
mvh/Regards
Kåre Olai Lindbach
------------------------------
Date: Wed, 19 Mar 2003 08:20:19 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: Array reference argument to subroutine problem
Message-Id: <MPG.18e238998b29d93c989751@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <slrnb7f4h1.pe7.jtc@flatland.dimensional.com>, Jim Cochrane
(jtc@flatland.dimensional.com) says...
> The web page "Passing Parameters to Functions" (
> http://www.cs.cf.ac.uk/Dave/PERL/node61.html#SECTION00920000000000000000
> ) describes how to use references to pass more than one array to a
> subroutine and distinguish between the two arrays in the subroutine.
> Unfortunately, on my system (perl -v5.6.1 on Redhat 7.3), this does not
> work. When I run the script below (the 2nd example on the above page),
> I get the following results:
>
> $ /tmp/ref.pl
> The first array is .
> The second array is .
>
> The web page says the output should be:
>
> The first array is 1 2 3 4 5.
> The second array is A B C D E.
>
> What's up here? Is my version of Perl too old? (I doubt it - it's not
> that old.) Is the page wrong? Something else - environment setting, ...?
>
> Thanks!
>
>
> #!/usr/bin/perl -w
>
> firstSub( (1..5), ("A".."E"));
>
> sub firstSub {
> my($ref_firstArray, $ref_secondArray) = @_;
>
> print("The first array is @{$ref_firstArray}.\n");
> print("The second array is @{$ref_secondArray}.\n");
> }
>
>
Your problem is that you are *not* passing the arrays as a reference to
the subroutine. Do it as follows :
#!/usr/bin/perl -w
firstSub( \(1..5), \("A".."E"));
sub firstSub {
my($ref_firstArray, $ref_secondArray) = @_;
print("The first array is @{$ref_firstArray}.\n");
print("The second array is @{$ref_secondArray}.\n");
}
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Wed, 19 Mar 2003 09:06:13 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Array reference argument to subroutine problem
Message-Id: <b5a118$i4n2@onews.collins.rockwell.com>
On 3/18/2003 5:55 PM, dw wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote:
>> dw <me@verizon.invalid> wrote:
>>> "Jim Cochrane" <jtc@flatland.dimensional.com> wrote:
>>>>
>>>> how to use references to pass more than one array to a
>>>> subroutine and distinguish between the two arrays in the
>>>> subroutine.
>>>
>>> firstSub( \(1..5), \("A".."E"));
>>
>> Why/how does that end up working? (I tried it with 5.6.1 & 5.8.0).
>>
>> perlref.pod says we should be getting 10 references from that, not
>> 2:
>
> [I]t appears to work this way when you use the range operator.
> According to perlop for the range operator, "In list context, it
> returns an array of values..."
Interesting. So the docs and behavior are consistent, even though this
behavior seems clearly wrong to anyone who (thinks they) know Perl.
> So in this example, the \(1..5) is referencing the list returned by
> the range operator. You will notice that doing \(1..5) is different
> from \(1,2,3,4,5).
Careful -- semantics are important here. A list and an array are subtly
different things. If '..' returned a _list_ (which is what I would have
expected), then the two forms would be equivilant. Because it returns an
_array_, they're not.
So why does '..' return an (anonymous) array instead of a list? That
makes the behavior of something like this seem very bizarre:
#!/usr/bin/perl -w
use Data::Dumper;
my @x = \(1 .. 3, 4);
print Dumper \@x;
__END__
$VAR1 = [
[
1,
2,
3
],
\4
];
-mjc
------------------------------
Date: Wed, 19 Mar 2003 10:17:41 -0500
From: AK <aknntp@yahoo.com>
Subject: Re: Cannot get authenticated to Yahoo's SMTP servers while sending mail using Net::SMTP
Message-Id: <md2h7v8l47fsq95kie94n6b63s4r91ikrf@4ax.com>
Thanks Tad, I appreciate your taking the time.
I will review all your suggestions/comments.
On Wed, 19 Mar 2003 06:11:25 -0600, tadmc@augustmail.com (Tad McClellan) wrote:
>AK <aknntp@yahoo.com> wrote:
>
>> (constructive suggestions/criticism for improvement are always welcome)
------------------------------
Date: 19 Mar 2003 08:23:52 -0800
From: google@rabb.org (Dan Rabb)
Subject: Date Calculation
Message-Id: <d685454c.0303190823.214019a7@posting.google.com>
Let me start by saying, I am a total newbie when it comes to Perl.
Beyond Perl, my programming experience is pretty slim too. With that
out of the way, I am hoping someone can provide me some guidance with
a problem I am having. I am trying to write a script that will grep
for some files, which all have filenames that begin with a date in the
format of YYYYMMDD.
In the script, I have a <STDIN> request for the date that I want to
search for. However, I would also like the script to search the day
before and the day after the requested date. Needless to say, I have
not been able to get this working yet. The problem is the <STDIN>
field is treated as a number, not a date, and therefore, adding one,
or subtracting one for that field, can give you a date of 20030300 or
20030132, for example. You get the point…
In an effort to experiment and learn a little, I wrote a small script
below which just deals with the date calculation portion of this
script. I have had many different revisions of this, but I figured if
I posted just one of them, it might give someone an idea of what I am
trying to accomplish. See below.
I have read many posts here that dealt with similar problems, and seen
suggestions of using EPOCH dates, to PCalc, etc. However, none of the
examples or references were close enough for a newbie like me to
translate to my specific problem.
Any guidance, references to documentation, examples, etc. would be
very much appreciated. Thank you in advance.
Dan Rabb
---snip---
print "Enter the date [YYYYMMDD] you wish to search for.\n" ;
$SEARCHDATE = <STDIN>;
chomp ($SEARCHDATE);
$DAYBEFORE = $SEARCHDATE - 1;
$DAYAFTER = $SEARCHDATE + 1;
print "The date entered was: $SEARCHDATE\n";
print "The date before was: $DAYBEFORE\n";
print "The date after will be: $DAYAFTER\n";
---snip---
Below are the results I mentioned:
---snip---
Enter the date [YYYYMMDD] you wish to search for.
20030301
The date entered was: 20030301
The date before was: 20030300
The date after will be: 20030302
Enter the date [YYYYMMDD] you wish to search for.
20030131
The date entered was: 20030131
The date before was: 20030130
The date after will be: 20030132
---snip---
------------------------------
Date: Wed, 19 Mar 2003 19:25:35 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Date Calculation
Message-Id: <pan.2003.03.19.16.43.00.643627@aursand.no>
On Wed, 19 Mar 2003 08:23:52 -0800, Dan Rabb wrote:
> In the script, I have a <STDIN> request for the date that I want to
> search for. However, I would also like the script to search the day
> before and the day after the requested date.
Use an appropriate Date module (found on CPAN). There are plenty of them,
and from the top of my head I can mention:
Date::Calc
Date::Manip
Class::Date
--
Tore Aursand
------------------------------
Date: 19 Mar 2003 10:24:38 -0800
From: Ethan Brown <ethan@draupnir.gso.saic.com>
Subject: Re: Date Calculation
Message-Id: <vrznnrjjtl.fsf@draupnir.gso.saic.com>
>>>>> "Dan" == Dan Rabb <google@rabb.org> writes:
Dan> Let me start by saying, I am a total newbie when it comes to Perl.
Dan> Beyond Perl, my programming experience is pretty slim too. With that
Dan> out of the way, I am hoping someone can provide me some guidance with
Dan> a problem I am having. I am trying to write a script that will grep
Dan> for some files, which all have filenames that begin with a date in the
Dan> format of YYYYMMDD.
There are a number of date modules on CPAN. Try the Date::Calc module.
--Ethan
------------------------------
Date: Wed, 19 Mar 2003 10:54:49 -0500
From: "Joly, Patrick: IAC" <Joly.Patrick@ic.gc.ca>
Subject: Re: Expression with varying number of conditions
Message-Id: <3E3612E8D41DD3118DCC060000000000099705B2@pubgate-01.ic.gc.ca>
Tad McClellan wrote,
> You are using keys from %hash1 to index into the _other_
> hashes?
>
> So all of the hashes are guaranteed to have exactly
> identical keys?
Yes, the keys are identical (they represent the observation (row)
number in a spreadsheet).
[snip]
>
> Now there is no doubt that your real problem is with the
> data structure you've chosen. Choose a different one. :-)
>
> Looks like LoH (list of hashes aka array of references to
> hashes) would be just the ticket. Instead of having N
> global hashes, have a single array containing N
> references to hashes.
>
> my @var;
> $var[0] = { hash1 => 'stuff goes here' };
> $var[1] = { hash2 => 'stuff goes here' };
> ...
> Then use $var[$j] instead of ${var$j}.
Point taken. I thought I could get away with symbolic references by
being careful (I read the links you posted, I am convinced and promise
not to do it again.) I decided to go with a HoA (hash of array refs)
which I think makes sense since they keys are identical.
and Benjamin Goldberg wrote,
> Hmm... Something like this:
>
> my $sortsub = "sub {\n" . join("\n\t\tor\n",
> map "\t\$hash$_{\$a} COMPARE \$hash$_{\$b}" 1 .. @_
> ) . ";\n}\n";
> for (@_) {
> if( /string/ ) {
> $sortsub =~ s/COMPARE/cmp/;
> } else {
> $sortsub =~ s/COMPARE/<=>/;
> }
> }
> warn $sortsub if $debugging;
> $sortsub = eval($sortsub) || die $@;
> @keys = sort $sortsub keys %hash1;
> [untested]
It works! Thanks to all for your suggestions. The end result is as
follows (NB: (1) this is my first OO module; (2) in my initial posting,
I had referred to object data by simply $var1, $var2, ..., for
simplicity)
sub sort { # method to sort data in class Stata::Data
my $self = shift;
if (@_) {
my (%HoA, @keys);
for my $n (0..$self->{N}) {
for my $k (0..$#_) {
$HoA{$n}[$k] =
$self->{DATA}->{"$_[$k]"}->{CELLS}[$n];
}
}
my $sortsub = "sub {\n" . join( "\n\t\tor\n",
map "\t" . '$HoA{$a}' . "[$_]" . " COMPARE$_ " .
'$HoA{$b}' . "[$_]", (0..$#_) ) . ";\n}\n";
for (0..$#_) {
if( $self->{DATA}->{"$_[$_]"}->{DISPLAY} =~ /s/ ) {
$sortsub =~ s/\bCOMPARE\Q$_\E\b/cmp/;
} else {
$sortsub =~ s/\bCOMPARE\Q$_\E\b/<=>/;
}
}
warn $sortsub if $main::debugging;
$sortsub = eval($sortsub) || die $@;
@keys = sort $sortsub keys %HoA;
# @keys will look like (4, 3, 1, 5, 2), the new order
# re-order all variables using @keys
for my $var (@{ $self->{ORDER} }) {
my ($pos, @new);
for (0..$#keys) {
$pos = "$keys[$_]";
$new[$_] = $self->{DATA}->{"$var"}->{CELLS}[$pos];
}
# and then overwrite @original by @new
@ { $self->{DATA}->{"$var"}->{CELLS} } = @new;
}
$self->{SORTEDBY} = join(" ", @_);
}
return $self->{SORTEDBY};
}
In case you are wondering what my data looks like, here is a data dump
(after the data has been sorted)
$VAR1 = bless( {
'ORDER' => [
'price',
'weight'
],
'NAME' => 'Pat\'s data',
'N' => '7',
'SORTEDBY' => 'weight price',
'LABEL' => 'My auto data',
'K' => 2,
'TSSET' => undef,
'DATA' => {
'weight' => {
'CELLS' => [
1200,
1500,
1500,
1500,
1500,
1500,
1650,
2000
],
'LABEL' => 'Weight of car',
'DISPLAY' => '%9.0g',
'TYPE' => undef
},
'price' => {
'CELLS' => [
-5,
-7,
80,
234,
253,
23980,
6,
292
],
'LABEL' => 'Price of car',
'DISPLAY' => '%9.0g',
'TYPE' => undef
}
}
}, 'Stata::Data' );
Thanks again to all!
Patrick Joly
joly.patrick@ic.gc.ca
------------------------------
Date: Wed, 19 Mar 2003 08:14:17 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: more efficent way to foreach ... $x.=$_
Message-Id: <MPG.18e237313ce9139a989750@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <3E774FA9.AFEF8659@someserver123abc.com>, stinkbomb
(user@someserver123abc.com) says...
> is there a more efficent way to:
>
> foreach (@db){
> $db.=$_;
> }
>
$db = join("",@db);
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Wed, 19 Mar 2003 18:16:51 GMT
From: "Vladimir P." <vladimir@NoSpamPLZ.net>
Subject: Re: perl ssh background process
Message-Id: <nu2ea.36600$8q2.558158@weber.videotron.net>
On 18 Mar 2003 07:11:44 -0800, Omega wrote:
> Respected Group,
>
> I have a problem while executing remote perl script. I use ssh from
> machine A. My perl script reside on Machine B.
> Machine A> ssh -l user machineB 'cd /home/user/cron; ./foo.pl
> 1>/dev/null 2>/dev/null' < /tmp/bar
Forget this shell thingy, install Net::SSH::Perl if you want something
reliable...
------------------------------
Date: 19 Mar 2003 08:00:55 -0800
From: alessandro.favretto@fracarro.com (Alessandro Favretto)
Subject: Re: perl-ldap problem
Message-Id: <8b4ef51a.0303190800.2a276112@posting.google.com>
Thank you very much Josef you solved my little problem.
Best regards
Josef Möllers <josef.moellers@fujitsu-siemens.com> wrote in message news:<3E6F1371.9F534665@fujitsu-siemens.com>...
> Alessandro Favretto wrote:
>
> > foreach $entry ($mesg->all entries->mail)
> > {
> > $entry->dump;
> > }
> >
>
> > This script work all right by shell script (it extract and display
> > cn,sn,mail),
> > but i would save the singles result (then cn,sn,mail in this case ) on
> > some variables, in this way i will able to generate web page.
>
> Have you tried the get value method?
>
> for($i = 0 ; $i < $mesg->count ; $i++) {
> my $entry = $mesg->entry($i);
> my $cn = $entry->get value("cn");
> my $sn = $entry->get value("sn");
> my $mail = $entry->get value("mail");
> }
------------------------------
Date: Wed, 19 Mar 2003 18:25:45 +0200
From: "Shlomit" <shlomit@stam.com>
Subject: Problem in conversion letter
Message-Id: <3e789a2c@news.012.net.il>
Hi,
I would like to convert a letter to bit base (by its ascii value) and then
to convert it back to its ascii value, but in char representation.
I run the following code on SUN-Solaris OS (Perl version is 5.006001):
$str = "A B";
@tmp = unpack("B8 B8 B8", $str);
foreach $item (@tmp) {
print "converted to bit: $item\n";
$ch = pack("c1", $item);
print "converted to char: $ch\n";
}
The output is:
converted to bit: 01000001
converted to char: A
converted to bit: 00100000
converted to char:
converted to bit: 01000010
converted to char: J
Each letter is converted to its corresponding ascii value in bin base
correctly (in 'converted to bit' print).
But it is not converted correctly from bits to char (in 'converted to char'
print).
Can anyone explain me what the problem is, and/or how to fix it?
Any help will be much appreciated.
Thanx,
Shlomit
------------------------------
Date: Wed, 19 Mar 2003 11:12:12 -0600
From: Bryan Krone <cbk047@email.mot.com>
Subject: Re: Problem in conversion letter
Message-Id: <3E78A4EC.27B7044C@email.mot.com>
Shlomit wrote:
>
> Hi,
>
> I would like to convert a letter to bit base (by its ascii value) and then
> to convert it back to its ascii value, but in char representation.
>
> I run the following code on SUN-Solaris OS (Perl version is 5.006001):
>
> $str = "A B";
>
> @tmp = unpack("B8 B8 B8", $str);
>
> foreach $item (@tmp) {
>
> print "converted to bit: $item\n";
>
> $ch = pack("c1", $item);
$item is being treated as a decimal number. 1000001d is 0xF4241 and the
"c1" converts the 0xXXX41 to an 'A', 01000010d is 0xF424A, 0xXXX4A gets
converted to 'J'.
$ch = pack( "B8", $item );
>
> print "converted to char: $ch\n";
>
> }
>
> The output is:
>
> converted to bit: 01000001
>
> converted to char: A
>
> converted to bit: 00100000
>
> converted to char:
>
> converted to bit: 01000010
>
> converted to char: J
>
> Each letter is converted to its corresponding ascii value in bin base
> correctly (in 'converted to bit' print).
>
> But it is not converted correctly from bits to char (in 'converted to char'
> print).
>
> Can anyone explain me what the problem is, and/or how to fix it?
>
> Any help will be much appreciated.
>
> Thanx,
>
> Shlomit
------------------------------
Date: Wed, 19 Mar 2003 18:19:17 GMT
From: "Vladimir P." <vladimir@NoSpamPLZ.net>
Subject: Re: Question about PERL modules EXPECT/Net::Telnet
Message-Id: <Fw2ea.36601$8q2.558324@weber.videotron.net>
On 18 Mar 2003 11:43:33 -0800, Brian Snyder wrote:
> Hi all,
>
> I am coding a perl script that will be responsible for kicking off a
> couple different telnet sessions and capturing their output. I
> believe I will get teh script to kick off multiple sessions
> simultaneously by making use of the fork() command.
Why use telnet if you can have your communication secured?
Try Net::SSH::Perl instead.
------------------------------
Date: Wed, 19 Mar 2003 18:29:31 +0200
From: "Shlomit" <shlomit@stam.com>
Subject: randomly curropted data
Message-Id: <3e789b0d$1@news.012.net.il>
Hi,
I'm running perl script on SUN-Solaris OS. Perl version is 5.006001
In general, the script gets data from remote computer over the network and
parses it.
My problem is that the data is not always read correctly by the script.
The script gets the data by using the <> operator and stores it in $_.
Before parsing it (using pack), it finds an offset by using index
("<something>", ${_}) and substr it by substr(${_}, $offset).
The problem is that sometimes, the data read correctly and sometimes not
(same character is read fine in one message and corrupted (garbage) in other
message).
After printing the data is hex-decimal base, I've noticed that the problem
is always in the left byte. For instance, a colon is represented (in hex)
sometimes as 3A (correct) and sometimes as BA (wrong).
The corrupted data occurs randomly.
I'm running almost the same code (the only different is that I use 'Read'
function instead of <> operator to get the input) on Unix-SCO (Perl version
is 5.00404) and everything works fine all data is read and converted
correctly.
Can someone explain me why?!!?!
Any help will be much appreciated.
Thanx,
Shlomit
------------------------------
Date: Wed, 19 Mar 2003 14:56:11 +0000
From: "Ahmad.J.Reeves" <ahmad@dcs.qmul.ac.uk>
Subject: running a script on multiple files in a directory
Message-Id: <b5a0eb$pc2$1@beta.qmul.ac.uk>
Hi,
I have a perl script that works on single files, but now I need it to
run on all files in a directory..
-----------------------------------------------------------------------
#!/usr/bin/perl
#
# get statistics about <div> sections
( $filename = $ARGV[0] ) or die "Error: must specify filename\n";
# slurp in whole file and flatten
open( FILE, "< $filename" ) or die "Error: can\'t open $filename\n";
@lines = <FILE>;
close( FILE ) or die "Error: can\'t close $filename\n";
( $text = "@lines" ) =~ s/\n//g;
# get header and find conversation IDs, plus number of participants
( ( $text =~ /(<teiHeader\b.*?<\/teiHeader>)/ ) and ( $header = $1 ) )
or die "Error: can\'t find header\n";
$nDiv = 0;
while ( $header =~
/<setting\b[^<>]*id=['"]([^'"]*)['"][^<>]*who=['"]([^'"]*)['"].*?<\/setting>/g
) {
$divID[$nDiv] = $1;
$nCP[$nDiv++] = split( /\w+/, $2 );
}
if ( $nDiv > 0 ) {
$totCP = $totTurns = $totSents = 0;
for ( $iDiv = 0; $iDiv < $nDiv; $iDiv++ ) {
( $text =~ /(<div\b[^<>]*$divID[$iDiv].*?<\/div>)/ ) or die
"Error: can\'t find div $iDiv\n";
$totCP += $nCP[$iDiv];
$totTurns += ( $nTurns[$iDiv] = split( /<u\b/, $1 ) - 1 );
$totSents += ( $nSents[$iDiv] = split( /<s\b/, $1 ) - 1 );
print "$divID[$iDiv]: $nCP[$iDiv] $nTurns[$iDiv] $nSents[$iDiv]\n";
}
@av = ( $totCP/$nDiv, $totTurns/$nDiv, $totSents/$nDiv );
print "Average: @av\n";
}
else {
print "no divs - probably not a dialogue file\n";
}
----------------------------------------------------
any ideas on the best way to do this?
Thanks in advance..
Ahmad
------------------------------
Date: Wed, 19 Mar 2003 15:07:00 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: running a script on multiple files in a directory
Message-Id: <3e788797$0$21982$cc9e4d1f@news.dial.pipex.com>
"Ahmad.J.Reeves" <ahmad@dcs.qmul.ac.uk> wrote in message
news:b5a0eb$pc2$1@beta.qmul.ac.uk...
> Hi,
>
> I have a perl script that works on single files, but now I need it to
> run on all files in a directory..
probably not the best way, but you could wrap this loop around your code:
#!/usr/bin/perl
my $dirtoread = "/home/yourdir/dir/"; #keep the end slash, use full path
my @filelist = `ls $dirtoread`; #get files and subdirectories into array
for (@filelist) {
my $file = $dirtoread.$_;
next if (-d $file); #ignore subdirectories
#....
#your code here - $file is the filename for the file
#....
}
Alex
---------------------------
http://www.alexite.com
------------------------------
Date: Wed, 19 Mar 2003 11:00:45 -0500
From: AK <aknntp@yahoo.com>
Subject: Re: running a script on multiple files in a directory
Message-Id: <jv4h7vcrajmdued3nh1vonvmjtq8s83f3e@4ax.com>
On Wed, 19 Mar 2003 14:56:11 +0000, "Ahmad.J.Reeves" <ahmad@dcs.qmul.ac.uk>
wrote:
>I have a perl script that works on single files, but now I need it to
>run on all files in a directory..
From the Cookbook:
Problem
You want to do something to each file in a particular directory.
Solution
Use opendir to open the directory and then readdir to retrieve every filename:
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
while (defined($file = readdir(DIR))) {
# do something with "$dirname/$file"
}
closedir(DIR);
- AK
------------------------------
Date: Wed, 19 Mar 2003 17:34:50 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: running a script on multiple files in a directory
Message-Id: <pan.2003.03.19.16.15.09.476263@aursand.no>
On Wed, 19 Mar 2003 14:56:11 +0000, Ahmad.J.Reeves wrote:
> I have a perl script that works on single files, but now I need it
> to run on all files in a directory.
Get all files from a specified directory:
opendir( DIR, '/tmp' ) or die "Can't open directory: $!\n";
my @files = readdir( DIR );
closedir( DIR );
Eventually, if you only want files with a specific suffix. '.html' in
this example:
my @files = grep /\.html$/ readdir( DIR );
> # slurp in whole file and flatten
> open( FILE, "< $filename" ) or die "Error: can\'t open $filename\n";
> @lines = <FILE>;
> close( FILE ) or die "Error: can\'t close $filename\n";
> ( $text = "@lines" ) =~ s/\n//g;
Hmm. I prefer this method;
open( FILE, '<' . $filename ) or die "Can't open file: $!\n";
my $text = '';
{
local $/ = undef;
$text = <FILE>;
}
close( FILE );
--
Tore Aursand
------------------------------
Date: Wed, 19 Mar 2003 12:31:22 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: running a script on multiple files in a directory
Message-Id: <slrnb7hdrq.4h9.tadmc@magna.augustmail.com>
Tore Aursand <tore@aursand.no> wrote:
> On Wed, 19 Mar 2003 14:56:11 +0000, Ahmad.J.Reeves wrote:
>> I have a perl script that works on single files, but now I need it
>> to run on all files in a directory.
> opendir( DIR, '/tmp' ) or die "Can't open directory: $!\n";
> Eventually, if you only want files with a specific suffix. '.html' in
> this example:
>
> my @files = grep /\.html$/ readdir( DIR );
And if you also want the directory part tacked back on:
my @fullpath_files = map "/tmp/$_", grep /\.html$/ readdir( DIR );
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 4730
***************************************