[32138] in Perl-Users-Digest
Perl-Users Digest, Issue: 3403 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 6 09:09:28 2011
Date: Mon, 6 Jun 2011 06:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 6 Jun 2011 Volume: 11 Number: 3403
Today's topics:
how to access thunderbird's address book. <pas@pourmois.be>
Re: How to keep SQL statement preparation and executing <rweikusat@mssgmbh.com>
Re: How to keep SQL statement preparation and executing <xhoster@gmail.com>
Howto conjoin information from two hash tables? <scottie383@gmail.com>
Re: Howto conjoin information from two hash tables? <tadmc@seesig.invalid>
Re: Howto conjoin information from two hash tables? <scottie383@gmail.com>
Re: Howto conjoin information from two hash tables? <scottie383@gmail.com>
Re: Howto conjoin information from two hash tables? <NoSpamPleaseButThisIsValid3@gmx.net>
Re: Howto conjoin information from two hash tables? <jimsgibson@gmail.com>
Re: Howto conjoin information from two hash tables? <scottie383@gmail.com>
Re: Howto conjoin information from two hash tables? <scottie383@gmail.com>
Re: Howto conjoin information from two hash tables? <bugbear@trim_papermule.co.uk_trim>
Re: Howto conjoin information from two hash tables? <tadmc@seesig.invalid>
Module for parsing .authinfo? <tim@tim-landscheidt.de>
Re: Module for parsing .authinfo? <uri@StemSystems.com>
Re: Module for parsing .authinfo? <tim@tim-landscheidt.de>
Re: Module for parsing .authinfo? <mvdwege@mail.com>
Re: Module for parsing .authinfo? <uri@StemSystems.com>
Re: Module for parsing .authinfo? <uri@StemSystems.com>
require statement <rahul_vasishta@yahoo.co.in>
Re: require statement <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 05 Jun 2011 09:09:40 GMT
From: Andre <pas@pourmois.be>
Subject: how to access thunderbird's address book.
Message-Id: <4deb47d4$0$14253$ba620e4c@news.skynet.be>
I am writing a script that send file by e-mail. I would like to select e-
mail adresses from thunderbird's address book. Is there a way to do this??
Many thanks in advances
Andre
------------------------------
Date: Sun, 05 Jun 2011 16:29:38 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: How to keep SQL statement preparation and executing code together
Message-Id: <87vcwks3dp.fsf@sapphire.mobileactivedefense.com>
Xho Jingleheimerschmidt <xhoster@gmail.com> writes:
> Rainer Weikusat wrote:
>> Marc Haber <mh+usenetspam1118@zugschl.us> writes:
>>> Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>>>> A pretty obvious idea would be
>>>>
>>>> sub do_something {
>>>> $sth = $dbh->prepare(...) or die unless $sth;
>>>> $sth->execute(...)
>>>>
>>>> .
>>>> .
>>>> .
>>>> }
>>> Neat idea. I'd go with Peter's suggestion nevertheless, I didn't know
>>> about prepare_cached before.
>>
>> This is actually almost the 'worst of both worlds' solution because it
>> implies that you still have the clutter of the prepare calls and the
>> local overhead of executing them
>
> What is the local overhead of executing them? Pretty close to zero.
The distance from here (Reading, UK) to Brisbane is also 'pretty close
to zero', compared to the distance between earth and say,
Sirius. OTOH, I will be going into the city to buy a couple of things
later and I won't first travel to Brisbane and back just because this
distance can be regarded as 'pretty close to zero' when viewed from a
particular perspective.
You statement really just means "I don't [want to] care about that".
Which is your prerogative, but an entirely tangetial point: The
runtime overhead is there can be avoided. And the maintenance overhead
of having to deal with twice as many lines of code, half of which have
essentially no purpose, is also there. I know, you don't care about
that, either.
>> and just save the IPC for the repeated prepares and the database
>> processing which would otherwise be
>> needed for executing them.
>
> Parsing and planning a query is quite resource intensive for many
> database servers, and is often well worth saving.
For a random database server and an equally random query where I just
tested this, the time needed to prepare the query was 0.00023s while
the time to execute it and return the result was 0.011036s, ie,
performing the query was about 48 times as expensive as preparing it.
Granted, I was cheating insofar as I selected a structurally simple
query whose execution was likely to be rather expensive. Conclusion:
Your general statement above is to general to be of any practical
value. Also, I didn't argue that avoiding the overhead to second half
the 'repeated prepare' would yield no benefit. I just pointed that the
first have also has an (avoidable) overhead.
>> Unless you're not really doing anything with the data except
>> invoking stored procedures which do the processing work inside the
>> DBMS and just return the results to you,
>
> Even without stored procedures, the DBMS does its part of the
> processing work inside itself and returns just the results to me.
> That is why I use one.
Except demonstrating that you didn't understand what I was writing,
this statement communicates very little ...
[...]
>> while the redundant local stuff
>> slows your processing down for nothing in return).
>
> I find that rather hard to believe.
Facts don't care for your belief in them.
------------------------------
Date: Sun, 05 Jun 2011 14:23:30 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: How to keep SQL statement preparation and executing code together
Message-Id: <4debf1ef$0$9777$ed362ca5@nr5-q3a.newsreader.com>
Rainer Weikusat wrote:
>> I find that rather hard to believe.
>
> Facts don't care for your belief in them.
Nor do they for yours. And since you have nothing but bluster and FUD
to offer....
Xho
------------------------------
Date: Sun, 5 Jun 2011 02:29:28 -0700 (PDT)
From: Scottie <scottie383@gmail.com>
Subject: Howto conjoin information from two hash tables?
Message-Id: <0f2727ac-8f76-4c4b-b76b-8807cf11b2e0@32g2000vbe.googlegroups.com>
Hi!
I'm stuck. Can you help me?
After the backup by Oracle RMAN tool I parse the log file and create
two hash tables:
%channel = #It collects information specific to channels
{ch1}
->[0] allocated channel: ch1
->[1] channel ch1: SID=596 device type=DISK
->[2] channel ch1: starting compressed full datafile backup set
->[3] channel ch1: specifying datafile(s) in backup set
{ch2}
->[0] allocated channel: ch2
->[1] channel ch2: SID=15 device type=DISK
->[2] channel ch2: starting compressed full datafile backup set
->[3] channel ch2: specifying datafile(s) in backup set
%channel_files = #It collects information about files that are
processed by the channel
{ch1}
->[0] input datafile file number=00014 name=/foo/oradata/foo/foo-
data04.dbf
->[1] input datafile file number=00019 name=/foo/oradata/foo/foo-
data05.dbf
{ch2}
->[0] input datafile file number=00013 name=/foo/oradata/foo/foo-
index03.dbf
->[1] input datafile file number=00012 name=/foo/oradata/foo/foo-
data03.dbf
I would like to concatenate information from the above two hash tables
into one line. Example result that I would get:
============================
Files for channel 'ch1':
Channel name Channel type File Number File Name
--------------- -------------- ----------------
---------------------------
ch1 DISK 00014 /foo/oradata/foo/foo-
data04.dbf
ch1 DISK 00019 /foo/oradata/foo/foo-
data05.dbf
Files for channel 'ch2':
Channel name Channel type File Number File Name
--------------- -------------- ----------------
---------------------------
ch2 DISK 00013 /foo/oradata/foo/foo-
index03.dbf
ch2 DISK 00012 /foo/oradata/foo/foo-
data03.dbf
============================
I will be grateful for your help.
Regards,
--
Scottie
------------------------------
Date: Sun, 05 Jun 2011 09:44:48 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <slrniun56v.j62.tadmc@tadbox.sbcglobal.net>
Scottie <scottie383@gmail.com> wrote:
> I'm stuck. Can you help me?
You are more likely to get help if you help us help you.
In order to help you, we would need to have the same data structure
that you have.
> %channel = #It collects information specific to channels
> {ch1}
> ->[0] allocated channel: ch1
> ->[1] channel ch1: SID=596 device type=DISK
> ->[2] channel ch1: starting compressed full datafile backup set
> ->[3] channel ch1: specifying datafile(s) in backup set
> {ch2}
> ->[0] allocated channel: ch2
> ->[1] channel ch2: SID=15 device type=DISK
> ->[2] channel ch2: starting compressed full datafile backup set
> ->[3] channel ch2: specifying datafile(s) in backup set
You should provide Real Perl Code that we can copy/paste rather
than pseudo-code.
This would have been fairly easy for you to do, it would have taken
about the same amount of time as it took to write the unusable pseudo-code.
Or, just
use Data::Dumper;
...
print Dumper \%channel;
Then copy/paste the output into your post.
Have you seen the Posting Guidelines that are posted here frequently?
> I would like to concatenate information from the above two hash tables
> into one line. Example result that I would get:
>============================
>
> Files for channel 'ch1':
> Channel name Channel type File Number File Name
> --------------- -------------- ----------------
> ---------------------------
> ch1 DISK 00014 /foo/oradata/foo/foo-
> data04.dbf
-------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my %channel = (
ch1 => [
'allocated channel: ch1',
'channel ch1: SID=596 device type=DISK',
'channel ch1: starting compressed full datafile backup set',
'channel ch1: specifying datafile(s) in backup set',
],
ch2 => [
'allocated channel: ch2',
'channel ch2: SID=15 device type=DISK',
'channel ch2: starting compressed full datafile backup set',
'channel ch2: specifying datafile(s) in backup set',
],
);
my %channel_files = (
ch1 => [
'input datafile file number=00014 name=/foo/oradata/foo/foo-data04.dbf',
'input datafile file number=00019 name=/foo/oradata/foo/foo-data05.dbf',
],
ch2 => [
'input datafile file number=00013 name=/foo/oradata/foo/foo-index03.dbf',
'input datafile file number=00012 name=/foo/oradata/foo/foo-data03.dbf',
],
);
foreach my $chan (sort keys %channel_files) {
print "Files for channel '$chan':\n";
printf "%-10s %-10s %-10s %s\n", 'Channel', 'type', 'Number', 'Name';
printf "%-10s %-10s %-10s %s\n", '-' x 10, '-' x 10, '-' x 10, '-' x 40;
my($type) = $channel{$chan}[1] =~ /type=(.*)/;
foreach my $file ( @{$channel_files{$chan}} ) {
my($num, $name) = $file =~ /number=(\d+)\s+name=(.*)/;
printf "%-10s %-10s %-10s %s\n", $chan, $type, $num, $name;
}
print "\n";
}
-------------------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sun, 5 Jun 2011 09:04:26 -0700 (PDT)
From: Scottie <scottie383@gmail.com>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <18c705ac-d522-4636-b201-67ad1de8e771@bl1g2000vbb.googlegroups.com>
Tad,
many, many thanks for your help. Your solution works perfectly and as
I expected! :)
On Jun 5, 4:44 pm, Tad McClellan <ta...@seesig.invalid> wrote:
> You are more likely to get help if you help us help you.
> In order to help you, we would need to have the same data structure
> that you have.
> (...)
> You should provide Real Perl Code that we can copy/paste rather
> than pseudo-code.
> (...)
> use Data::Dumper;
Okay. Next time I'll remember to use this module.
Best regards,
--
Scottie
------------------------------
Date: Sun, 5 Jun 2011 12:55:51 -0700 (PDT)
From: Scottie <scottie383@gmail.com>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <cf049aa6-363c-4f42-b4bb-9cb6a47311a9@gh5g2000vbb.googlegroups.com>
Tad, or some other Perl hacker.
I have a one, small additional question. Is it possible to sort output
by file number order?
my %channel = (
ch1 => [
'allocated channel: ch1',
'channel ch1: SID=596 device type=DISK',
'channel ch1: starting compressed full datafile backup set',
'channel ch1: specifying datafile(s) in backup set',
'channel ch1: backup set complete, elapsed time: 00:00:15',
'released channel: ch1'
],
ch2 => [
'allocated channel: ch2',
'channel ch2: SID=15 device type=DISK',
'channel ch2: starting compressed full datafile backup set',
'channel ch2: specifying datafile(s) in backup set',
'channel ch2: backup set complete, elapsed time: 00:00:01',
'released channel: ch2'
]
);
my %channel_files =(
ch1 => [
'input datafile file number=00014 name=/foo/oradata/foo/foo-
data04.dbf',
'input datafile file number=00019 name=/foo/oradata/foo/foo-
data05.dbf',
'input datafile file number=00002 name=/foo/oradata/foo/foo-
index06.dbf',
],
ch2 => [
'input datafile file number=00013 name=/foo/oradata/foo/foo-
index03.dbf',
'input datafile file number=00012 name=/foo/oradata/foo/foo-
data03.dbf',
'input datafile file number=00011 name=/foo/oradata/foo/foo-
index02.dbf',
]
};
For example:
BEFORE:
====================================================
Files for channel 'ch1':
Channel type Number Name
---------- ---------- ----------
----------------------------------------
ch1 DISK 00014 /foo/oradata/foo/foo-data04.dbf
ch1 DISK 00019 /foo/oradata/foo/foo-data05.dbf
Files for channel 'ch2':
Channel type Number Name
---------- ---------- ----------
----------------------------------------
ch2 DISK 00013 /foo/oradata/foo/foo-index03.dbf
ch2 DISK 00012 /foo/oradata/foo/foo-data03.dbf
====================================================
AFTER (sort):
====================================================
Files for channel 'ch1':
Channel type Number Name
---------- ---------- ----------
----------------------------------------
ch1 DISK 00002 /foo/oradata/foo/foo-index06.dbf
ch1 DISK 00014 /foo/oradata/foo/foo-data04.dbf
ch1 DISK 00019 /foo/oradata/foo/foo-data05.dbf
Files for channel 'ch2':
Channel type Number Name
---------- ---------- ----------
----------------------------------------
ch2 DISK 00011 /foo/oradata/foo/foo-index02.dbf
ch2 DISK 00012 /foo/oradata/foo/foo-data03.dbf
ch2 DISK 00013 /foo/oradata/foo/foo-index03.dbf
====================================================
Thanks in advance.
P.S. Sorry for Google (Groups), which breaks lines after 60
character. :-/
Regards,
--
Scottie
------------------------------
Date: Sun, 05 Jun 2011 23:59:27 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <4debfc41$0$6629$9b4e6d93@newsspool2.arcor-online.net>
On 05.06.2011 21:55, Scottie wrote:
> Tad, or some other Perl hacker.
> I have a one, small additional question. Is it possible to sort output
> by file number order?
Yes. See "perldoc -f sort" or search the web for "Schwartzian
transformation".
You only need to replace Tad's inner foreach loop:
foreach my $fileref (sort {$a->[0] <=> $b->[0]}
map { [/number=(\d+)\s+name=(.*)/] }
@{$channel_files{$chan}} ) {
printf "%-10s %-10s %-10s %s\n", $chan, $type, @$fileref;
}
The trick is that you first filter out number and name and map these two
values in an array. Then it becomes simple to sort. The first map of the
usual "map sort map" sequence is not needed here.
- Wolf
------------------------------
Date: Sun, 05 Jun 2011 15:15:37 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <050620111515378377%jimsgibson@gmail.com>
In article
<cf049aa6-363c-4f42-b4bb-9cb6a47311a9@gh5g2000vbb.googlegroups.com>,
Scottie <scottie383@gmail.com> wrote:
> Tad, or some other Perl hacker.
> I have a one, small additional question. Is it possible to sort output
> by file number order?
Yes. Extract the file number from your data and sort by that in your
print loop. You can do this one of three (at least) ways:
1. Reorganize your data so that file number is an explicit element of
your data and can be used to sort the data for printing.
2. Extract the file number on the fly, associate it with each data
line, sort the lines by file number, and print the data. In Perl, this
can be done in one (long) statement (see 'Schwartzian Transform').
3. Parse the data, extracting the data to be printed, but save it in a
temporary data structure instead of printing it. Then, sort the data by
file number and print it.
>
> my %channel = (
> ch1 => [
[snipped]
> );
>
> my %channel_files =(
> ch1 => [
> 'input datafile file number=00014 name=/foo/oradata/foo/foo-
> data04.dbf',
> 'input datafile file number=00019 name=/foo/oradata/foo/foo-
> data05.dbf',
> 'input datafile file number=00002 name=/foo/oradata/foo/foo-
> index06.dbf',
> ],
> ch2 => [
> 'input datafile file number=00013 name=/foo/oradata/foo/foo-
> index03.dbf',
> 'input datafile file number=00012 name=/foo/oradata/foo/foo-
> data03.dbf',
> 'input datafile file number=00011 name=/foo/oradata/foo/foo-
> index02.dbf',
> ]
> };
The file number is embedded in the strings that are members of
anonymous, referenced arrays. However, the substring preceding each
number is identical, so you can simply sort the data lines to put the
lines in order by file number.
>
>
> For example:
> BEFORE:
> ====================================================
> Files for channel 'ch1':
> Channel type Number Name
> ---------- ---------- ----------
> ----------------------------------------
> ch1 DISK 00014 /foo/oradata/foo/foo-data04.dbf
> ch1 DISK 00019 /foo/oradata/foo/foo-data05.dbf
>
> Files for channel 'ch2':
> Channel type Number Name
> ---------- ---------- ----------
> ----------------------------------------
> ch2 DISK 00013 /foo/oradata/foo/foo-index03.dbf
> ch2 DISK 00012 /foo/oradata/foo/foo-data03.dbf
> ====================================================
>
> AFTER (sort):
> ====================================================
> Files for channel 'ch1':
> Channel type Number Name
> ---------- ---------- ----------
> ----------------------------------------
> ch1 DISK 00002 /foo/oradata/foo/foo-index06.dbf
> ch1 DISK 00014 /foo/oradata/foo/foo-data04.dbf
> ch1 DISK 00019 /foo/oradata/foo/foo-data05.dbf
>
> Files for channel 'ch2':
> Channel type Number Name
> ---------- ---------- ----------
> ----------------------------------------
> ch2 DISK 00011 /foo/oradata/foo/foo-index02.dbf
> ch2 DISK 00012 /foo/oradata/foo/foo-data03.dbf
> ch2 DISK 00013 /foo/oradata/foo/foo-index03.dbf
> ====================================================
The BEFORE and AFTER contain differing amount of data. Is that
significant?
If you want more help, please post some working Perl code (short as
possible that demonstrates whatever problem you are having.)
--
Jim Gibson
------------------------------
Date: Mon, 6 Jun 2011 03:13:58 -0700 (PDT)
From: Scottie <scottie383@gmail.com>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <b242063b-047c-4112-9ea2-cc0463ab3f9d@p21g2000yqh.googlegroups.com>
On Jun 5, 11:59=A0pm, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@gmx.net> wrote:
> You only need to replace Tad's inner foreach loop:
> =A0 =A0 foreach my $fileref (sort {$a->[0] <=3D> $b->[0]}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0map { [/number=3D(\d+)=
\s+name=3D(.*)/] }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0@{$channel_files{$chan=
}} ) {
> =A0 =A0 =A0 =A0 printf "%-10s %-10s %-10s %s\n", $chan, $type, @$fileref;
> =A0 =A0 }
Wolf,
for (my $i=3D0; $i<=3D100; $i++) {
print "Thank you very much!\n";
}
and Thank you! :-) Your code (sort function) works magnificently!
BTW, I read somewhere that using the map operator distinguishes
ordinary programmers from the good programmers. I would not be able to
write a sorting function using the operator map. But I'm not a
programmer, just a DBA.
Sincerely,
--
Scottie
------------------------------
Date: Mon, 6 Jun 2011 03:16:43 -0700 (PDT)
From: Scottie <scottie383@gmail.com>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <80d9cab8-78ae-4a07-8e19-746e9ae2f4a9@l18g2000yql.googlegroups.com>
On Jun 6, 12:15=A0am, Jim Gibson <jimsgib...@gmail.com> wrote:
> Yes. Extract the file number from your data and sort by that in your
> print loop. You can do this one of three (at least) ways:
Jim,
I also thank you for your guidance. It's very helpful for me. :)
Scottie
------------------------------
Date: Mon, 06 Jun 2011 11:35:48 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <e_Cdna84ju4ZMHHQnZ2dnUVZ8smdnZ2d@brightview.co.uk>
Scottie wrote:
> and Thank you! :-) Your code (sort function) works magnificently!
> BTW, I read somewhere that using the map operator distinguishes
> ordinary programmers from the good programmers.
That was probably written by someone who'd just
found the map function, and was very proud of the fact.
BugBear
------------------------------
Date: Mon, 06 Jun 2011 08:05:51 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Howto conjoin information from two hash tables?
Message-Id: <slrniupjpc.m9v.tadmc@tadbox.sbcglobal.net>
Scottie <scottie383@gmail.com> wrote:
> for (my $i=0; $i<=100; $i++) {
Writing a for loop like that one is a Very Bad Habit to get into.
It is hard to read and very effective at injecting an "off by one" bug.
We have enough bugs to chase without helping ourselves to inject
yet more bugs...
The loop executes 101 times.
Is that what you expected, or did you expect 100 times?
If you want 100 iterations, then The Better Way is:
foreach my $i ( 0 .. 99 ) {
or
foreach my $i ( 1 .. 100 ) {
If you really wanted 101 iterations with $i taking values starting at
zero, then:
foreach my $i ( 0 .. 100 ) {
> BTW, I read somewhere that using the map operator distinguishes
> ordinary programmers from the good programmers.
Either that is a load of hooey, or you have paraphrased it incorrectly.
*knowing when* to use the map operator distinguishes ordinary
programmers from the good programmers.
If you want to get a filtered list, use grep().
If you want to get a transformed list, use map().
If you want to interate over a list, use foreach().
eg. get a list where every element is in lower case:
# ordinary programmer
my @lower;
foreach my $elem (@list) {
push @lower, lc($elem);
}
# good programmer
my @lower = map {lc} @list;
or
my @lower = map {lc $_} @list;
or
my @lower = map lc($_), @list;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sun, 05 Jun 2011 18:45:55 +0000
From: Tim Landscheidt <tim@tim-landscheidt.de>
Subject: Module for parsing .authinfo?
Message-Id: <m3k4d09kws.fsf@passepartout.tim-landscheidt.de>
Hi,
is there any existing module for parsing .authinfo files?
TIA,
Tim
------------------------------
Date: Sun, 05 Jun 2011 15:15:37 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Module for parsing .authinfo?
Message-Id: <87y61grsx2.fsf@quad.sysarch.com>
>>>>> "TL" == Tim Landscheidt <tim@tim-landscheidt.de> writes:
TL> is there any existing module for parsing .authinfo files?
did you search cpan for that?
and even if there isn't a specific module, it is a trivial space seperated value
file format. that means you can likely use a CSV module and set space as
the delimiter. then it comes down to assigning that to a hash since each
line is a set of key value pairs. and skipping # comment lines. this is
about 7 lines of code even without a module.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sun, 05 Jun 2011 19:44:11 +0000
From: Tim Landscheidt <tim@tim-landscheidt.de>
Subject: Re: Module for parsing .authinfo?
Message-Id: <m3fwno9i7o.fsf@passepartout.tim-landscheidt.de>
"Uri Guttman" <uri@StemSystems.com> wrote:
> TL> is there any existing module for parsing .authinfo files?
> did you search cpan for that?
Yes, of course. There's only Net::Netrc which I found after
going through Gnus' source and it's inflexible with regard
to the filename.
> and even if there isn't a specific module, it is a trivial space seperated value
> file format. that means you can likely use a CSV module and set space as
> the delimiter. then it comes down to assigning that to a hash since each
> line is a set of key value pairs. and skipping # comment lines. this is
> about 7 lines of code even without a module.
... and skip empty lines, and treat quoted values, and nor-
malize white space, and process continuation lines and, and,
and. Interestingly, Net::Netrc uses many more than seven
lines.
Looking forward to your rewrite,
Tim
------------------------------
Date: Sun, 05 Jun 2011 23:08:49 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: Module for parsing .authinfo?
Message-Id: <86wrh0vvdq.fsf@gareth.avalon.lan>
Tim Landscheidt <tim@tim-landscheidt.de> writes:
> "Uri Guttman" <uri@StemSystems.com> wrote:
>
>> TL> is there any existing module for parsing .authinfo files?
>
>> did you search cpan for that?
>
> Yes, of course. There's only Net::Netrc which I found after
> going through Gnus' source and it's inflexible with regard
> to the filename.
>
>> and even if there isn't a specific module, it is a trivial space
>> seperated value file format. that means you can likely use a CSV
>> module and set space as the delimiter. then it comes down to
>> assigning that to a hash since each line is a set of key value
>> pairs. and skipping # comment lines. this is about 7 lines of code
>> even without a module.
>
> ... and skip empty lines,
next if ...
> and treat quoted values, and nor- malize white space,
Text::CSV does that for you.
> and process continuation lines
The Perl Cookbook contains a recipe to normalize lines with continuation
marks. Use that to normalize your file before feeding it to Text::CSV.
> and, and, and. Interestingly, Net::Netrc uses many more than seven
> lines.
>
> Looking forward to your rewrite,
Looking forward to you doing your own homework before starting to snark
at people trying to help you.
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Sun, 05 Jun 2011 17:23:04 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Module for parsing .authinfo?
Message-Id: <87sjrorn0n.fsf@quad.sysarch.com>
>>>>> "MvdW" == Mart van de Wege <mvdwege@mail.com> writes:
MvdW> Tim Landscheidt <tim@tim-landscheidt.de> writes:
>> "Uri Guttman" <uri@StemSystems.com> wrote:
>>
TL> is there any existing module for parsing .authinfo files?
>>
>>> did you search cpan for that?
>>
>> Yes, of course. There's only Net::Netrc which I found after
>> going through Gnus' source and it's inflexible with regard
>> to the filename.
>>
>>> and even if there isn't a specific module, it is a trivial space
>>> seperated value file format. that means you can likely use a CSV
>>> module and set space as the delimiter. then it comes down to
>>> assigning that to a hash since each line is a set of key value
>>> pairs. and skipping # comment lines. this is about 7 lines of code
>>> even without a module.
>>
>> ... and skip empty lines,
MvdW> next if ...
that is too much code!
>> and treat quoted values, and nor- malize white space,
MvdW> Text::CSV does that for you.
oh, so hard!
>> and process continuation lines
MvdW> The Perl Cookbook contains a recipe to normalize lines with continuation
MvdW> marks. Use that to normalize your file before feeding it to Text::CSV.
can't read and code at the same time!
>> Looking forward to your rewrite,
MvdW> Looking forward to you doing your own homework before starting to snark
MvdW> at people trying to help you.
agreed.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sun, 05 Jun 2011 18:56:05 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Module for parsing .authinfo?
Message-Id: <871uz7sxa2.fsf@quad.sysarch.com>
>>>>> "TL" == Tim Landscheidt <tim@tim-landscheidt.de> writes:
TL> Looking forward to your rewrite,
now you owe me $100. or a massive apology. your choice. this took all of
15 minutes, half of which was rereading the docs on Text::CSV since i
rarely use it. it doesn't handle continuation lines but i leave that as
an exercise to you. you might as well do something here. and you can
make it into a proper a module and put it on cpan and contribute
something back to the perl community. or pay me another $100. i take
paypal.
oh, it was *10* lines of main code (excluding use lines and such).
uri
#!/usr/bin/perl
use warnings ;
use strict ;
use File::Slurp ;
use Text::CSV ;
my %auth_info ;
my $home = eval { (getpwuid($>))[7] } || $ENV{HOME} ;
my $auth_file = shift || "$home/.authinfo" ;
my $csv = Text::CSV->new( { sep_char => ' ' } ) ;
my @auth_lines = grep !/^(#.*|\s*)$/, read_file( $auth_file ) ;
foreach my $line ( @auth_lines ) {
$csv->parse( $line ) ;
my %auth_parts = $csv->fields();
$auth_info{ $auth_parts{machine} } = \%auth_parts ;
}
use Data::Dumper ;
print Dumper \%auth_info ;
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Mon, 6 Jun 2011 05:43:37 -0700 (PDT)
From: "Rahul!!" <rahul_vasishta@yahoo.co.in>
Subject: require statement
Message-Id: <77fbf99f-7039-46f2-abf6-ba8a53393f22@q12g2000prb.googlegroups.com>
Hello all,
What is the best practice to avoid hard coded paths? Consider
following code snippet,
#!/usr/bin/perl
#myscript
use strict;
require "/usr/home/wakow/admin.pm";
require "/usr/home/wakow/config.pl";
What is the best way to remove the hard coded paths set in the script?
It should work even if I use relative path while invoking the script
like this,
perl ../../../myscript.pl
------------------------------
Date: Mon, 06 Jun 2011 13:56:53 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: require statement
Message-Id: <8762ojxgmi.fsf@sapphire.mobileactivedefense.com>
"Rahul!!" <rahul_vasishta@yahoo.co.in> writes:
> Hello all,
>
> What is the best practice to avoid hard coded paths? Consider
> following code snippet,
> #!/usr/bin/perl
> #myscript
> use strict;
>
> require "/usr/home/wakow/admin.pm";
> require "/usr/home/wakow/config.pl";
>
> What is the best way to remove the hard coded paths set in the
> script?
The two options which suggest themselves would be
- install into one of the 'standard' Perl library
directories
- set the PERL5LIB environment variable to some suitable
value before running the code
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3403
***************************************