[30428] in Perl-Users-Digest
Perl-Users Digest, Issue: 1671 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 24 11:09:51 2008
Date: Tue, 24 Jun 2008 08:09:13 -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 Tue, 24 Jun 2008 Volume: 11 Number: 1671
Today's topics:
Re: change a single digit to corresponding English word <xiaoxia2005a@yahoo.com>
Re: change a single digit to corresponding English word <tzz@lifelogs.com>
Re: change a single digit to corresponding English word <benkasminbullock@gmail.com>
Re: change a single digit to corresponding English word <noreply@gunnar.cc>
Re: change a single digit to corresponding English word <jurgenex@hotmail.com>
Re: FAQ 5.12 How can I open a filehandle to a string? (David Combs)
Re: FAQ 9.16 How do I decode a CGI form? <npc@zomg.tk>
Re: FAQ 9.16 How do I decode a CGI form? <jurgenex@hotmail.com>
Forcing list context for C<glob> (was: Problem expandin <whynot@pozharski.name>
Re: Forcing list context for C<glob> (was: Problem expa xhoster@gmail.com
Re: Forcing list context for C<glob> (was: Problem expa <ben@morrow.me.uk>
Re: I hate CGI.pm <fawaka@gmail.com>
SendingHTML files via e-mail <btna@terra.com>
Re: SendingHTML files via e-mail <noreply@gunnar.cc>
What is GDBM_File and Fcntl ? Please comment this piece <ahmad.abdulghany@gmail.com>
Re: What is GDBM_File and Fcntl ? Please comment this p <RedGrittyBrick@SpamWeary.foo>
Re: What is GDBM_File and Fcntl ? Please comment this p xhoster@gmail.com
Re: What is GDBM_File and Fcntl ? Please comment this p <ben@morrow.me.uk>
Why no more "who-posts-most-here" reports? Was pretty (David Combs)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 24 Jun 2008 04:51:57 -0700 (PDT)
From: April <xiaoxia2005a@yahoo.com>
Subject: Re: change a single digit to corresponding English word
Message-Id: <c337bade-c73a-45ab-becb-ba0b7d4fd94b@k30g2000hse.googlegroups.com>
On Jun 23, 11:19=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> April <xiaoxia20...@yahoo.com> wrote:
> >Will the following change a single digit to corresponding English
> >word, like 3 to three, 5 to five, etc?
>
> >$char =3D $numbers[$char]
>
> Assuming that the array @numbers contains the string 'three' at index 3,
> then yes, after this assignment $char will contain the string 'three'.
> In which case $char is a very poor choice for an identifier.
>
> jue
Thanks jue and everyone .. I just stumble on this and would like to
know how this "$char =3D $numbers[$char]" accually work ... here is the
entire program:
#!/usr/bin/perl -w
use strict;
my @numbers =3D qw(zero one two three four five six seven eight nine);
print "Enter a string containing a number: ";
chomp(my $answer =3D <STDIN>);
my @characters =3D split ("", $answer);
foreach my $char (@characters)
{
$char =3D $numbers[$char]
if ($char ge "0" && $char le "9");
}
print "The output is: @characters\n";
------------------------------
Date: Tue, 24 Jun 2008 08:09:18 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: change a single digit to corresponding English word
Message-Id: <8663rzm135.fsf@lifelogs.com>
On Tue, 24 Jun 2008 00:42:09 -0600 "Jack D" <jack@home.net> wrote:
JD> "April" <xiaoxia2005a@yahoo.com> wrote in message
JD> news:3f8e4157-755b-426e-92a5-0d0fe7b241b6@k13g2000hse.googlegroups.com...
>> Will the following change a single digit to corresponding English
>> word, like 3 to three, 5 to five, etc?
>>
>> $char = $numbers[$char]
JD> In addition to the answers already given, I thought I would also point
JD> out that there is a module that does this very thing:
JD> http://search.cpan.org/~sburke/Lingua-EN-Numbers-1.01/
I wonder if there's a locale-sensitive way to say numbers from inside
Perl. It must be available (part of glibc I think), since I know `date`
for example can print the day correctly depending on the locale.
I didn't see anything in CPAN, only
http://search.cpan.org/~rgarcia/perl-5.10.0/ext/I18N/Langinfo/Langinfo.pm
The CPAN *Locale* modules were not very useful for this task.
Lingua::Any::Numbers doesn't sniff out the locale automatically, and
doesn't seem to use the glibc facilities (if such exist).
Ted
------------------------------
Date: Tue, 24 Jun 2008 13:26:54 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: change a single digit to corresponding English word
Message-Id: <g3qsmt$oco$1@ml.accsnet.ne.jp>
On Tue, 24 Jun 2008 08:09:18 -0500, Ted Zlatanov wrote:
> On Tue, 24 Jun 2008 00:42:09 -0600 "Jack D" <jack@home.net> wrote:
> JD> In addition to the answers already given, I thought I would also point
> JD> out that there is a module that does this very thing:
>
> JD> http://search.cpan.org/~sburke/Lingua-EN-Numbers-1.01/
This is rather a handy module by the way.
> I wonder if there's a locale-sensitive way to say numbers from inside
> Perl. It must be available (part of glibc I think), since I know `date`
> for example can print the day correctly depending on the locale.
Dates are a different issue from numbers. I'm fairly sure glibc has
nothing as fancy as this. But there are some modules which deal with
numbers, like Lingua::JA::Numbers, which you can see in action on my
website:
http://convert.sljfaq.org/numbers.cgi
Generally, converting numbers into a string of text is rather a
difficult problem requiring a lot of knowledge of the language you
want to write the number in. It's not something which one would expect
to find in a C library.
> I didn't see anything in CPAN, only
> http://search.cpan.org/~rgarcia/perl-5.10.0/ext/I18N/Langinfo/Langinfo.pm
>
> The CPAN *Locale* modules were not very useful for this task.
>
> Lingua::Any::Numbers doesn't sniff out the locale automatically, and
> doesn't seem to use the glibc facilities (if such exist).
Lingua::Any::Numbers seems to be nothing but a wrapper for various
other Perl modules, like the above-mentioned Lingua::JA::Numbers.
------------------------------
Date: Tue, 24 Jun 2008 15:35:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: change a single digit to corresponding English word
Message-Id: <6ccbhfF3f8n1vU1@mid.individual.net>
April wrote:
> Thanks jue and everyone .. I just stumble on this and would like to
> know how this "$char = $numbers[$char]" accually work ... here is the
> entire program:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my @numbers = qw(zero one two three four five six seven eight nine);
>
> print "Enter a string containing a number: ";
> chomp(my $answer = <STDIN>);
>
> my @characters = split ("", $answer);
>
> foreach my $char (@characters)
> {
>
> $char = $numbers[$char]
> if ($char ge "0" && $char le "9");
> }
>
> print "The output is: @characters\n";
I suggest that you do some reading first.
perldoc perlintro
perldoc perldata
If you don't understand the above code after having studied those parts
of the docs, then come back and ask a more specific question.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 24 Jun 2008 13:43:43 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: change a single digit to corresponding English word
Message-Id: <0fu164ht0hcc4hatea2vcpdbb6n4q4mnq4@4ax.com>
April <xiaoxia2005a@yahoo.com> wrote:
> I just stumble on this and would like to
>know how this "$char = $numbers[$char]" accually work
Do you know what an array is and how to access its elements?
jue
------------------------------
Date: Tue, 24 Jun 2008 14:52:47 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 5.12 How can I open a filehandle to a string?
Message-Id: <g3r1nv$c6s$1@reader2.panix.com>
The suggested examples and uses all concern writing *to* a string.
How about for reading *from* a string?
What are some of the (possible) uses for doing that?
And -- what about "peek" on such a thing?
And a "putback", as for when you have to look-ahead?
-----
Re reading *and writing* to/from a string (pretending to be
an open file), what are some of the useful perl-operations
already existing for *files*, for which there's no corresponding
perl-op for *strings*, which you can get at via the kludge
of pretending it's a file?
I think such a discussion here (in the faq) could lead to
lots of interesting (and useful!) programming-tricks!
David
------------------------------
Date: Tue, 24 Jun 2008 13:22:15 +0200 (CEST)
From: Hans Bulvai <npc@zomg.tk>
Subject: Re: FAQ 9.16 How do I decode a CGI form?
Message-Id: <g3qld7$6nn$1@aioe.org>
>> But if you want to use JavaScript, CSS, or any encoding other than
>> ASCII, CGI.pm will make your life miserable. I've been there and done
>> that, and my experience has been that CGI.pm is a pain in the neck.
>
> When did JavaScript or CSS become "encodings"? CSS is a style sheet
> language, that is either inlined into an x?html document or in an
> external document referenced from an x?html document. JavaScript/JS is a
> client side (and server side in the case of ASP) scripting language that
> too can appear within or linked externally from an x?html document.
He meant 'encoding' only to refer to the last item of his list, i.e.
things that will make your life miserable:
1) javascript
2) css
3) using other encodings besides ascii
------------------------------
Date: Tue, 24 Jun 2008 13:48:04 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 9.16 How do I decode a CGI form?
Message-Id: <9iu1649ic95jeos6p3ukj1dkbte3rja08t@4ax.com>
Hans Bulvai <npc@zomg.tk> wrote:
>things that will make your life miserable:
[...]
>3) using other encodings besides ascii
Yeah. And not using other encodings besides ASCII makes other peoples
life miserable. I can't count the number of times my first name got
mangled despite all computers/OSs produced in this millenium will
happily handle ISO-Latin-1 resp. Windows-1252 by default.
jue
------------------------------
Date: Tue, 24 Jun 2008 10:34:51 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Forcing list context for C<glob> (was: Problem expanding filenames in loop)
Message-Id: <rlk6j5x1oj.ln2@carpet.zombinet>
Ben Morrow <ben@morrow.me.uk> wrote:
*SKIP*
>> {
>> $File=glob("/backups/backupfiles/*/$Volume");
> glob in scalar context doesn't do what you think. Once you've invoked it
> once, it ignores its argument until it's returned all the possible
> results and then undef. If you just want the first result, you need to
> call it in list context like this:
> my ($File) = glob(...);
> where the parens around ($File) make this a list assignment (into a list
> with only one value) rather than a scalar assignment.
As of Perl 5.8.8 (for Debian Etch) it makes no difference:
09:57:37 14 [0:9]$ perl -e '($x) = glob q(/*); print $x, "\n"; print
glob(q(/var/*)), "\n"'
/bin
/var/backups/var/cache/var/games/var/lib/var/local/var/lock/var/log
/var/lost+found/var/mail/var/opt/var/quota.group/var/quota.user/var/run
/var/spool/var/state/var/tmp/var/www
09:57:49 15 [0:0]$ perl -e '$x = glob q(/*); print $x, "\n"; print
glob(q(/var/*)), "\n"'
/bin
/var/backups/var/cache/var/games/var/lib/var/local/var/lock/var/log
/var/lost+found/var/mail/var/opt/var/quota.group/var/quota.user/var/run
/var/spool/var/state/var/tmp/var/www
09:57:58 16 [0:0]$ perl -e '$x = glob q(/*); print $x, "\n"; print
glob(), "\n"; print glob(q(/var/*)), "\n"'
/bin
/var/backups/var/cache/var/games/var/lib/var/local/var/lock/var/log
/var/lost+found/var/mail/var/opt/var/quota.group/var/quota.user/var/run
/var/spool/var/state/var/tmp/var/www
09:59:27 17 [0:0]$ perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
[Stealing thread]
(Sorry for somewhat messy screenshots) However, I have (had?) a problem
with B<forcing> list context for C<glob> in order to B<count>
occurences. I've tried:
10:15:35 23 [0:0]$ perl -e 'print glob q(/*); print "\n"'
/bin/boot/cdrom/cdrom0/dev/etc/floppy/home/initrd.img/initrd.img.old
/lib/lost+found/media/mnt/opt/proc/root/sbin/sys/tmp/usr/var/vmlinuz
/vmlinuz.old
10:15:44 24 [0:0]$ perl -e 'print (glob q(/*)); print "\n"'
/bin/boot/cdrom/cdrom0/dev/etc/floppy/home/initrd.img/initrd.img.old
/lib/lost+found/media/mnt/opt/proc/root/sbin/sys/tmp/usr/var/vmlinuz
/vmlinuz.old
10:16:12 25 [0:0]$ perl -e 'print scalar(glob q(/*)); print "\n"'
/bin
10:16:21 26 [0:0]$ perl -e 'print scalar((glob q(/*))); print "\n"'
/bin
And ended with:
10:16:30 27 [0:0]$ perl -e 'print scalar(@{[ glob q(/*) ]}); print "\n"'
24
That looks somewhat awful, doesn't it? OK, after all I want to count.
That doesn't work (I don't understand DWIM?) too:
10:21:32 30 [0:0]$ perl -e 'print glob q(/*) > 1; print "\n"'
10:23:00 31 [0:0]$ perl -e 'print (glob q(/*)) > 1; print "\n"'
/bin/boot/cdrom/cdrom0/dev/etc/floppy/home/initrd.img/initrd.img.old
/lib/lost+found/media/mnt/opt/proc/root/sbin/sys/tmp/usr/var/vmlinuz
/vmlinuz.old
10:23:20 32 [0:0]$ perl -e 'print (glob q(/*)) > 1; print "\n"'
10:23:26 32 [0:1]$ perl -e 'print scalar(glob q(/*)) > 1; print "\n"'
10:23:58 33 [0:0]$ perl -e 'print scalar((glob q(/*))) > 1; print "\n"'
10:24:07 34 [0:0]$ perl -e 'print scalar(@{[ glob q(/*) ]}) > 1; print
"\n"'
1
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: 24 Jun 2008 14:45:36 GMT
From: xhoster@gmail.com
Subject: Re: Forcing list context for C<glob> (was: Problem expanding filenames in loop)
Message-Id: <20080624104537.502$1E@newsreader.com>
Eric Pozharski <whynot@pozharski.name> wrote:
> Ben Morrow <ben@morrow.me.uk> wrote:
>
> *SKIP*
> >> {
> >> $File=glob("/backups/backupfiles/*/$Volume");
>
> > glob in scalar context doesn't do what you think. Once you've invoked
> > it once, it ignores its argument until it's returned all the possible
> > results and then undef. If you just want the first result, you need to
> > call it in list context like this:
>
> > my ($File) = glob(...);
>
> > where the parens around ($File) make this a list assignment (into a
> > list with only one value) rather than a scalar assignment.
>
> As of Perl 5.8.8 (for Debian Etch) it makes no difference:
It isn't clear to me what difference you think it should make.
>
> 09:57:37 14 [0:9]$ perl -e '($x) = glob q(/*); print $x, "\n"; print
> glob(q(/var/*)), "\n"'
The above has no loops. Neither of the globs in the above is encountered
twice. Each occurrence of glob-in-scalar-context maintains its own
iterator state. To have one global iterator for all globs in the program
would be bizarre. (Even more bizarre)
...
>
> [Stealing thread]
>
> (Sorry for somewhat messy screenshots) However, I have (had?) a problem
> with B<forcing> list context for C<glob> in order to B<count>
> occurences. I've tried:
..
> And ended with:
>
> 10:16:30 27 [0:0]$ perl -e 'print scalar(@{[ glob q(/*) ]}); print "\n"'
> 24
>
> That looks somewhat awful, doesn't it?
perl -e 'print scalar(() = glob q(/*)); print "\n"'
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 24 Jun 2008 15:50:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Forcing list context for C<glob> (was: Problem expanding filenames in loop)
Message-Id: <i7e7j5-8a5.ln1@osiris.mauzo.dyndns.org>
Quoth Eric Pozharski <whynot@pozharski.name>:
> Ben Morrow <ben@morrow.me.uk> wrote:
>
> *SKIP*
> >> {
> >> $File=glob("/backups/backupfiles/*/$Volume");
>
> > glob in scalar context doesn't do what you think. Once you've invoked it
> > once, it ignores its argument until it's returned all the possible
> > results and then undef. If you just want the first result, you need to
> > call it in list context like this:
>
> > my ($File) = glob(...);
>
> > where the parens around ($File) make this a list assignment (into a list
> > with only one value) rather than a scalar assignment.
>
> As of Perl 5.8.8 (for Debian Etch) it makes no difference:
You're testing the wrong thing... which is not surprising, since where
Perl keeps its implicit iterators is never very clear. Scalar glob keeps
its iterator *in the op*: that is, each instance of 'glob' in the source
is iterating independantly. So you have to call the same one twice to
see any odd effects:
~% perl -le'print glob("/bin") for 1..2'
/bin
/bin
~% perl -le'print scalar glob("/bin") for 1..2'
/bin
~%
or indeed
~% perl -le'print glob("/$_") for qw/bin usr/'
/bin
/usr
~% perl -le'print scalar glob("/$_") for qw/bin usr/'
/bin
~%
> 09:57:37 14 [0:9]$ perl -e '($x) = glob q(/*); print $x, "\n"; print
> glob(q(/var/*)), "\n"'
(you would do well to learn about the -l switch... :) )
<snip>
> (Sorry for somewhat messy screenshots) However, I have (had?) a problem
> with B<forcing> list context for C<glob> in order to B<count>
> occurences. I've tried:
>
> 10:15:35 23 [0:0]$ perl -e 'print glob q(/*); print "\n"'
glob is in list context.
> 10:15:44 24 [0:0]$ perl -e 'print (glob q(/*)); print "\n"'
glob is still in list context: the extra parens around print's arguments
make no difference.
> 10:16:12 25 [0:0]$ perl -e 'print scalar(glob q(/*)); print "\n"'
glob is in scalar context, so it iterates.
> 10:16:21 26 [0:0]$ perl -e 'print scalar((glob q(/*))); print "\n"'
glob is still in scalar context: more layers of parens still don't make
any difference.
> 10:16:30 27 [0:0]$ perl -e 'print scalar(@{[ glob q(/*) ]}); print "\n"'
OK, that works; but as you say, it's ugly, and it constructs a
completely useless array.
> 10:21:32 30 [0:0]$ perl -e 'print glob q(/*) > 1; print "\n"'
glob is in scalar context and returns '/bin'. '/bin' is numerically
equal to 0, so it is not greater than 1, so '>' returns false.
> 10:23:00 31 [0:0]$ perl -e 'print (glob q(/*)) > 1; print "\n"'
glob is in list context; the return value of print (1, probably) is
compared to 1, and the result thrown away. If you'd used -w you'd have
got a warning about that.
> 10:23:26 32 [0:1]$ perl -e 'print scalar(glob q(/*)) > 1; print "\n"'
This is the same as 'glob() > 1'. The 'scalar' is superflous.
> 10:23:58 33 [0:0]$ perl -e 'print scalar((glob q(/*))) > 1; print "\n"'
Same here.
> 10:24:07 34 [0:0]$ perl -e 'print scalar(@{[ glob q(/*) ]}) > 1; print
> "\n"'
This works correctly, but again is deeply ugly.
The idiom you are looking for is
my $x = () = glob(...);
or, if you need a 'scalar',
print scalar( () = glob(...) );
I have no idea where this is documented, but if you assign to the empty
list in scalar context it returns a count of the items in the assigned
list. This is weird and not at all the way any other list assignment
works, but surprisingly useful.
Ben
--
Although few may originate a policy, we are all able to judge it.
Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: Tue, 24 Jun 2008 16:20:55 +0200
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: I hate CGI.pm
Message-Id: <517a0$486102c7$89e0e08f$13472@news1.tudelft.nl>
> What do other people think of it? Am I a lone CGI.pm hater, or do other
> people use some superior system instead of CGI.pm?
>
I don't CGI is a bad system, and in the past I have used it on a number
of projects. It's form-handling is quite good IMHO. Having said that,
these days there are plenty of more capable system out there.
> I tried to read the documentation for Catalyst, and it makes no sense to
> me - it looks like you have to buy a book and spend hours and hours to
> understand it. Since I don't usually even write web things, I don't want
> to spend a lot of time studying the systems - I just want a "better CGI
> module". Does it exist?
>
Catalyst may or may not be an overkill for your needs, but I can't
recommend anything without knowing what you really want. Perhaps Jifty is
more like what you're looking for.
Cheers,
Leon
------------------------------
Date: Tue, 24 Jun 2008 06:30:36 -0700 (PDT)
From: btna <btna@terra.com>
Subject: SendingHTML files via e-mail
Message-Id: <3b929057-a8c2-415d-aa0f-718391085e11@26g2000hsk.googlegroups.com>
Hi all,
I am trying to write a simple Perl script that will accept the HTML
file as one argument and then send an e-mail with the HTML file. I
don't want the HTML file attached to the e-mail but to be part of the
body of the e-mail. In other words, I need the HTML file that I am
sending to be the actual body of the e-mail.
I am new to Perl so this is what I have so far:
use strict;
use MIME::Lite;
use Date::Calc qw(:all);
# SendTo email id
my $to_id = 'aaa@abc.com';
my $filename=$ARGV[0];
chomp (my $date = `date +%A" "%B" "%d","%Y`);
my $subject = sprintf("SAN Capacity Report:
%s",Date_to_Text_Long(Today()));
# create a new MIME Lite based email
my $msg = MIME::Lite->new
(
From => 'root@abc.com',
To => $to_id,
Subject => $subject,
Type => 'multipart/mixed',
);
$msg->send();
I am not sure how to make the $filename which is the HTML file passed
to the script so it gets sent as part of the body of the e-mail.
Any help would be appreciate it.
Thanks,
BTNA
------------------------------
Date: Tue, 24 Jun 2008 15:50:39 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: SendingHTML files via e-mail
Message-Id: <6cccdpF3eqrtgU1@mid.individual.net>
btna wrote:
> I am not sure how to make the $filename which is the HTML file passed
> to the script so it gets sent as part of the body of the e-mail.
I'm not sure either, but did you read the docs for MIME::Lite?
perldoc MIME::Lite
It contains several examples that ought to work as a guidance.
Try to modify your script with help of the docs, and come back if you
don't find a solution that way.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 24 Jun 2008 07:27:33 -0700 (PDT)
From: Ahmad <ahmad.abdulghany@gmail.com>
Subject: What is GDBM_File and Fcntl ? Please comment this piece of code
Message-Id: <436bc41b-ffca-4d10-8472-5619de896bcc@k30g2000hse.googlegroups.com>
Hi ,
I'm newbie in Perl, and I have some Perl scripts that contains some
text processing.
In the piece of Perl code shown below:
What do the following lines mean? What are the "Fcntl" and
"GDBM_File" ? Finally, what is the usage of "tie" and "untie"
functions, and what type of arguments are passed to them below?!
use Fcntl;
use GDBM_File;
tie %datain001,GDBM_File,"IRD_db/mainarea_db", O_RDWR | O_CREAT, 0644;
....
....
untie %datain001;
Thanks and regards
Ahmad
------------------------------
Date: Tue, 24 Jun 2008 15:48:26 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: What is GDBM_File and Fcntl ? Please comment this piece of code
Message-Id: <4861093c$0$2490$da0feed9@news.zen.co.uk>
Ahmad wrote:
> Hi ,
>
> I'm newbie in Perl, and I have some Perl scripts that contains some
> text processing.
>
> In the piece of Perl code shown below:
> What do the following lines mean? What are the "Fcntl" and
> "GDBM_File" ?
They are Perl modules. A bit like subroutine/class/method libraries in
other programming languages.
You can read about them by opening a command prompt and typing#
perldoc Fcntl
perldoc GDBM_File
> Finally, what is the usage of "tie" and "untie"
> functions, and what type of arguments are passed to them below?!
See
perldoc -f tie
perldoc -f untie
perldoc perltie
>
> use Fcntl;
> use GDBM_File;
> tie %datain001,GDBM_File,"IRD_db/mainarea_db", O_RDWR | O_CREAT, 0644;
> ....
> ....
> untie %datain001;
>
You might want to read an introductory tutorial first ...
http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/tie_a_hash.html
--
RGB
------------------------------
Date: 24 Jun 2008 14:53:38 GMT
From: xhoster@gmail.com
Subject: Re: What is GDBM_File and Fcntl ? Please comment this piece of code
Message-Id: <20080624105339.796$wL@newsreader.com>
Ahmad <ahmad.abdulghany@gmail.com> wrote:
> Hi ,
>
> I'm newbie in Perl, and I have some Perl scripts that contains some
> text processing.
As a newbie, one of the first things you should do is learn how to
use the docs.
> In the piece of Perl code shown below:
> What do the following lines mean? What are the "Fcntl" and
> "GDBM_File" ?
On a linux command line, I type "perldoc Fcntl" and get:
NAME
Fcntl - load the C Fcntl.h defines
....
And for "perldoc GDBM_File":
NAME
GDBM_File - Perl5 access to the gdbm library.
....
> Finally, what is the usage of "tie" and "untie"
> functions, and what type of arguments are passed to them below?!
perldoc -f tie
perldoc -f untie
> use Fcntl;
> use GDBM_File;
> tie %datain001,GDBM_File,"IRD_db/mainarea_db", O_RDWR | O_CREAT, 0644;
The overall effect is that stuff put into the hash %datain001 is now stored
on disk in the file IRD_db/mainarea_db, rather than in RAM.
The purpose of Fcntl is to define O_RDWR and O_CREAT
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 24 Jun 2008 16:02:25 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What is GDBM_File and Fcntl ? Please comment this piece of code
Message-Id: <1te7j5-8a5.ln1@osiris.mauzo.dyndns.org>
Quoth Ahmad <ahmad.abdulghany@gmail.com>:
>
> I'm newbie in Perl, and I have some Perl scripts that contains some
> text processing.
>
> In the piece of Perl code shown below:
> What do the following lines mean? What are the "Fcntl" and
> "GDBM_File" ? Finally, what is the usage of "tie" and "untie"
> functions, and what type of arguments are passed to them below?!
>
> use Fcntl;
> use GDBM_File;
Fcntl and GDBM_File are modules; that is, pieces of Perl code (and
sometimes C code) that have already been written for you. 'use' is the
Perl keyword for pulling a module into your program: if you are familiar
with C, it's like a combination of '#include <foo.h>' and '-lfoo' on the
link line. Most other languages have some equivalent facility.
From your point of view, as a user of modules, all you need to know to
start with is that 'use' pulls a module in, and you can pass the module
arguments. To find out what the module does, and what arguments it
takes, you need to read 'perldoc Module'; that is, in this case, you
would type
perldoc Fcntl
at your command line and read the text it gives you. (Of course, if you
don't know what <fcntl.h> is that won't help you much; essentially Fcntl
provides you with definitions of O_RDWR and O_CREAT that you use below.)
> tie %datain001,GDBM_File,"IRD_db/mainarea_db", O_RDWR | O_CREAT, 0644;
'tie' attaches some 'magic' to a variable, meaning that when you read
and write its value something unusual happens. In this case, you're
using the magic provided by the GDBM_File module, which makes the
entries in the named database appear as elements in the hash.
> untie %datain001;
'untie' undoes the 'tie' above; an explicit 'untie' is usually a
mistake.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: 24 Jun 2008 10:39:17 -0400
From: dkcombs@panix.com (David Combs)
Subject: Why no more "who-posts-most-here" reports? Was pretty nice!
Message-Id: <g3r0ul$cd3$1@panix1.panix.com>
From time to time, someone would post a who-posted-most,
who-responded-most, etc, report on the group.
Was pretty nice!
Whatever happened to it?
Did anyone find it useful, even interesting?
Enough so to get it going again?
Thanks,
David
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1671
***************************************