[19802] in Perl-Users-Digest
Perl-Users Digest, Issue: 1997 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 24 09:05:35 2001
Date: Wed, 24 Oct 2001 06:05:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003928717-v10-i1997@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 Oct 2001 Volume: 10 Number: 1997
Today's topics:
capture image <pydc@hotmail.com>
Re: capture image <bernard.el-hagin@lido-tech.net>
Formatting numbers - decimal places <tomboss2@hotmail.com>
Re: Formatting numbers - decimal places <simon.oliver@umist.ac.uk>
Re: Formatting numbers - decimal places <whatever@nevermind.invalid>
Re: Formatting numbers - decimal places <sguazt@infodrome.net>
frage zum datum <paule.p-deleteme-@gmx.de>
Re: frage zum datum <diehard@nospam.userve.co.uk>
Re: frage zum datum <paule.p-deleteme-@gmx.de>
Re: frage zum datum <mgjv@tradingpost.com.au>
Re: frage zum datum <ronan.oconnor@materna.nl>
Re: frage zum datum <paule.p-deleteme-@gmx.de>
Re: Hiding the content of a Perl Script <f.galassi@e-mind.it>
Re: How to display text file in cgi-bin? <bart.lateur@skynet.be>
Length of an Array or hash <peter_laranc@yahoo.com>
Re: Length of an Array or hash <bernard.el-hagin@lido-tech.net>
New Perl User Group (UK) (DarkBlue)
Re: Newbie cgi pm <please@no.spam>
Re: NEWBIE: Sorting a hash by value <stevoarnold@yahoo.co.uk>
Perl and SNMP <terrie@wiredcity.com.au>
Regexp help needed please --- I think <dot@dot.dot>
Re: Regexp help needed please --- I think <bernard.el-hagin@lido-tech.net>
Re: Regexp help needed please --- I think <bernard.el-hagin@lido-tech.net>
Re: Regexp help needed please --- I think <dot@dot.dot>
Search File <gclark@wavetel.com>
Re: Search File <bernard.el-hagin@lido-tech.net>
Shareware version of pl-2-exe ? <milos.obradovic@alcatel.com>
Re: Shareware version of pl-2-exe ? <bernard.el-hagin@lido-tech.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Oct 2001 20:17:19 +0800
From: "huan" <pydc@hotmail.com>
Subject: capture image
Message-Id: <3bd6afae_2@news.tm.net.my>
hi,
i want to know how to capture an image from internet using perl, i have some
codes below, but it seem not work:-
#!/usr/bin/perl -w
use LWP::Simple;
print "Content-Type: image/gif\n\n";
$content = get("http://xxx.com/xxx.jpg");
print $content;
exit;
------------------------------
Date: 24 Oct 2001 12:22:57 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: capture image
Message-Id: <slrn9tdc8u.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Oct 2001 20:17:19 +0800, huan <pydc@hotmail.com> wrote:
> hi,
>
> i want to know how to capture an image from internet using perl, i have some
> codes below, but it seem not work:-
What does "it seem not work" mean? Did you get an error message?
Did you *not* get the image you expected to get? Did nothing happen?
Cheers,
Bernard
------------------------------
Date: Wed, 24 Oct 2001 11:37:18 +0100
From: "Tomas" <tomboss2@hotmail.com>
Subject: Formatting numbers - decimal places
Message-Id: <9r65pk$u3b$1@kermit.esat.net>
New to Perl so bear with me...
I have a share feed that I am outputting on a web site. The information
comes as a number to 2 decimal places most of the time but sometimes comes
with only 1 decimal place when it is a round number... e.g. it could be
54.63 or else 13.1
What do I have to do to make the 13.1 output as 13.10?
Thanks for any advice.
Tom
------------------------------
Date: Wed, 24 Oct 2001 13:27:14 +0100
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Tomas <tomboss2@hotmail.com>
Subject: Re: Formatting numbers - decimal places
Message-Id: <3BD6B3A1.9D240440@umist.ac.uk>
sprintf "%.2f", '13.1'
Tomas wrote:
>
> New to Perl so bear with me...
> I have a share feed that I am outputting on a web site. The information
> comes as a number to 2 decimal places most of the time but sometimes comes
> with only 1 decimal place when it is a round number... e.g. it could be
> 54.63 or else 13.1
> What do I have to do to make the 13.1 output as 13.10?
> Thanks for any advice.
> Tom
------------------------------
Date: Wed, 24 Oct 2001 08:29:51 -0400
From: asif <whatever@nevermind.invalid>
Subject: Re: Formatting numbers - decimal places
Message-Id: <3BD6B43F.2040202@nevermind.invalid>
Tomas wrote:
> New to Perl so bear with me...
> I have a share feed that I am outputting on a web site. The information
> comes as a number to 2 decimal places most of the time but sometimes comes
> with only 1 decimal place when it is a round number... e.g. it could be
> 54.63 or else 13.1
> What do I have to do to make the 13.1 output as 13.10?
> Thanks for any advice.
> Tom
>
>
>
sprintf is your friend.
/whatever
------------------------------
Date: Wed, 24 Oct 2001 14:32:04 +0200
From: "Marco Guazzone" <sguazt@infodrome.net>
Subject: Re: Formatting numbers - decimal places
Message-Id: <9r6c7o$aa$1@serv1.iunet.it>
printf '%.2f', $num;
or in general:
my $decimals = ... # num of decimals (2 in this case)
printf '%.*f', $decimals, $num;
Marco Guazzone
marco.guazzone@kerbero.com
Kerbero.com
"Tomas" <tomboss2@hotmail.com> wrote in message
news:9r65pk$u3b$1@kermit.esat.net...
> New to Perl so bear with me...
> I have a share feed that I am outputting on a web site. The information
> comes as a number to 2 decimal places most of the time but sometimes comes
> with only 1 decimal place when it is a round number... e.g. it could be
> 54.63 or else 13.1
> What do I have to do to make the 13.1 output as 13.10?
> Thanks for any advice.
> Tom
>
>
------------------------------
Date: Wed, 24 Oct 2001 12:21:15 +0200
From: Falk P. <paule.p-deleteme-@gmx.de>
Subject: frage zum datum
Message-Id: <5d5dttouhhou9ac95dijmv9qrodnqooo5m@4ax.com>
hi,
ein kurze frage:
wie kann ich am elegantesten aus diesem datum (yyyy-mm-dd hh-mm-ss):
[2001-1-4 12:1:5]
dieses:
[2001-01-04 12:01:05]
erzeugen? (Oder von vornherein 2-stellige angaben erhalten?)
vielen dank!
------------------------------
Date: Wed, 24 Oct 2001 11:26:15 +0100
From: "Diehard Duck" <diehard@nospam.userve.co.uk>
Subject: Re: frage zum datum
Message-Id: <1003919177.7022.0.nnrp-02.9e98e2c7@news.demon.co.uk>
"Falk P." <paule.p-deleteme-@gmx.de> wrote in message
news:5d5dttouhhou9ac95dijmv9qrodnqooo5m@4ax.com...
> hi,
>
> ein kurze frage:
>
> wie kann ich am elegantesten aus diesem datum (yyyy-mm-dd hh-mm-ss):
>
> [2001-1-4 12:1:5]
>
> dieses:
>
> [2001-01-04 12:01:05]
>
> erzeugen? (Oder von vornherein 2-stellige angaben erhalten?)
>
> vielen dank!
Roughly translater for you:
Hi, a small question:
What is the most elegant way I can convert into this date format (yyyy mm dd
HHMMSS):
[ 2001-1-4 12:1:5 ]
into this:
[ 2001-01-04 12:01:05 ]
?
* Another bit here I don't understand *
thank you!
--
Ðiehard ÐuçK
------------------------------
Date: Wed, 24 Oct 2001 12:40:27 +0200
From: Falk P. <paule.p-deleteme-@gmx.de>
Subject: Re: frage zum datum
Message-Id: <ej6dttgd8l8mjlvdj2e6v493ldq1gq110t@4ax.com>
hi,
>Roughly translater for you:
sorry :) forgot to translate it - thanks you!
mfg
------------------------------
Date: Wed, 24 Oct 2001 20:53:00 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: frage zum datum
Message-Id: <slrn9td7cc.uue.mgjv@martien.heliotrope.home>
On Wed, 24 Oct 2001 12:21:15 +0200,
Falk P <paule.p-deleteme-@gmx.de> wrote:
> hi,
>
> ein kurze frage:
>
> wie kann ich am elegantesten aus diesem datum (yyyy-mm-dd hh-mm-ss):
>
> [2001-1-4 12:1:5]
>
> dieses:
>
> [2001-01-04 12:01:05]
>
> erzeugen?
One way:
my $date = "[2001-1-4 12:1:5]";
my @date = $date =~ /\[(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)]/;
$date = sprintf "[%04d-%02d-%02d %02d:%02d:%02d]", @date;
or in one go, without the temporary array:
$date = sprintf "[%04d-%02d-%02d %02d:%02d:%02d]",
$date =~ /\[(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)]/;
And, if you're sure there are no other digits in your string anywhere:
$date = sprintf "[%04d-%02d-%02d %02d:%02d:%02d]", $date =~ /(\d+)/g;
but I'd be a bit reticent to use something as generic as that last one.
> (Oder von vornherein 2-stellige angaben erhalten?)
You could of course use sprintf to start with. Are you implying that you
actually created that date string yourself? Have a look at the
documentation for sprintf in the perlfunc manual page, but also have a
look at strftime in the POSIX manual page.
Martien
--
|
Martien Verbruggen | life ain't fair, but the root
| password helps. -- BOFH
|
------------------------------
Date: Wed, 24 Oct 2001 13:02:18 +0200
From: "Ronan O'Connor" <ronan.oconnor@materna.nl>
Subject: Re: frage zum datum
Message-Id: <9r67fi$40j$1@penthesilea.materna.de>
You probably want to use the "sprintf" function.
Suggested plan of action:
split the date into its component parts
@array = split/-|\s+|:/; # Getting rid of the brackets [] is left as an
exercise!
for each part that needs "padding" use the sprintf function
$new = sprintf("%.2d",$old); # assuming you want to have double digit
figures (1 -> 01, 5 -> 05 etc)
Put it all back together again :)
Falk P. <paule.p-deleteme-@gmx.de> wrote in message
news:5d5dttouhhou9ac95dijmv9qrodnqooo5m@4ax.com...
> hi,
>
> ein kurze frage:
>
> wie kann ich am elegantesten aus diesem datum (yyyy-mm-dd hh-mm-ss):
>
> [2001-1-4 12:1:5]
>
> dieses:
>
> [2001-01-04 12:01:05]
>
> erzeugen? (Oder von vornherein 2-stellige angaben erhalten?)
>
> vielen dank!
------------------------------
Date: Wed, 24 Oct 2001 13:40:34 +0200
From: Falk P. <paule.p-deleteme-@gmx.de>
Subject: Re: frage zum datum
Message-Id: <v4adttg88knf6neo5b80tbo4ucbloc0tcm@4ax.com>
thanks for the answers!
mfg
------------------------------
Date: Wed, 24 Oct 2001 10:01:31 GMT
From: Fe <f.galassi@e-mind.it>
Subject: Re: Hiding the content of a Perl Script
Message-Id: <234dtt4t20r0qf8jgr8c634ghtta74b3l2@4ax.com>
On 24 Oct 2001 00:58:32 -0700, kalin@vivax-tech.com (Kalin) wrote:
perldoc -q hide
perldoc perlcompile
Filter::* hierarchy
>Hi,
>
>I'm working on a project that requires the content of the Perl Scripts
>not to be seen. I was wondering if there is a way to do that?
>
>Let me know if you know a solution.
>
>Thanks,
>
>Kalin
------------------------------
Date: Wed, 24 Oct 2001 10:11:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to display text file in cgi-bin?
Message-Id: <tp4dttk56dl110fdpar17jje10kmaj0orn@4ax.com>
Jerry McEwen wrote:
>I have a shopping cart several levels deep in my cgi-bin directory and
>orders get written to a file in a sub-folder. We have SSL and I want
>my client to be able to access orders.txt via https, but Perl (or
>maybe the server's config?) prevents the file from being displayed.
>
>My host tells me that I will have to get a script to display it, but I
>can't find one. Any thoughts? Thanks!
Move your shopping cart tree out of cgi-bin. Data files do not belong in
there! Preferably, move it to a file tree out of the web space.
Reference it through absolute paths in your script.
In order to display such a file, you can create a simple script that
prints a content-type header with 'text/plain', opens such a file, reads
every line and print it to STDOUT. But MSIE probably won't like it.
--
Bart.
------------------------------
Date: Wed, 24 Oct 2001 12:46:44 +0200
From: "Peter" <peter_laranc@yahoo.com>
Subject: Length of an Array or hash
Message-Id: <9r64vq$aet$1@newstoo.ericsson.se>
Hi
I have some beginier question, how could i find the length of an Array or a
Hash ?
and How can i check if an array or hash is empty or not ?
If an array looks like
[
'192.66.10.80',
'192.66.10.81',
'147.215.1.12',
'192.66.10.88',
'192.66.10.83',
];
and the hash looks like
{
2 => {
Name =>'Patrik',
},
3 => {
Name =>'Mark',
},
};
Thanks alot Peter
------------------------------
Date: 24 Oct 2001 11:05:48 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Length of an Array or hash
Message-Id: <slrn9td7o9.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Oct 2001 12:46:44 +0200, Peter <peter_laranc@yahoo.com> wrote:
>
> Hi
>
> I have some beginier question, how could i find the length of an Array or a
> Hash ?
# for arrays
my $length = @array;
print $length;
# for hashes
my $length = keys %hash;
print $length;
> and How can i check if an array or hash is empty or not ?
$length will be 0.
> If an array looks like
> [
> '192.66.10.80',
> '192.66.10.81',
> '147.215.1.12',
> '192.66.10.88',
> '192.66.10.83',
> ];
That's an anonymous array. To find its length you have to dereference
the reference created by the above statement. So if you have an
anon array created like this:
my $a_ref = [];
you can find its length like this:
my $length = @$a_ref;
> and the hash looks like
>
> {
> 2 => {
> Name =>'Patrik',
> },
>
> 3 => {
> Name =>'Mark',
> },
> };
Here you have an anonymous hash of anonymous hashes. Here the length
will be the amount of anon hashes within the hash:
my $h_ref = {};
my $length = keys %$h_ref;
Cheers,
Bernard
------------------------------
Date: 24 Oct 2001 04:20:39 -0700
From: wypug-admin@digital-word.com (DarkBlue)
Subject: New Perl User Group (UK)
Message-Id: <e5148510.0110240320.21c57ac7@posting.google.com>
WYPUG (West Yorkshire Perl User Group) has been established to serve
the Perl community in the West Yorkshire area (UK). Membership is
free and open to everyone.
The groups main aims are:
o to offer help and troubleshooting to our members through our mailing
lists, IRC channels, web forums and, naturally, regular meetings
o to publish articles and tutorials (amongst other content) via our
website (http://wypug.pm.org/, http://wypug.digital-word.com/)
o to contribute to the open-source community via CPAN through
collaborative projects
o to provide our members with discounted books (courtesy of O'Reilly &
Associates)
o to host an annual conference (potentially)
o to provide group packages for travel and accommodation to events
such as YAPC (where possible)
We are now trying to build an editorial team to write interesting and
informative articles and tutorials for the WYPUG website. If anyone
is interested in writing for WYPUG then please don't hesitate to
contact me.
Thank you.
Jonathan - WYPUG
WYPUG is an O'Reilly and Perl Mongers sponsored user group.
------------------------------
Date: Wed, 24 Oct 2001 10:05:13 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Newbie cgi pm
Message-Id: <87u1wp2w55.fsf@homer.cghm>
Dave Cross <dave@dave.org.uk> writes:
> 1/ There's no need to include both :standard and :html3 as :standard
> includes :html3
Funny. That's true, but some sample code in the CGI man page includes
both.
------------------------------
Date: Wed, 24 Oct 2001 11:18:34 +0100
From: "Steve" <stevoarnold@yahoo.co.uk>
Subject: Re: NEWBIE: Sorting a hash by value
Message-Id: <9r64oe$lin$1@pheidippides.axion.bt.co.uk>
"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3bd62dc4.333706083@news.erols.com...
> On Tue, 23 Oct 2001 17:27:34 +0100, Jasper McCrea
> <jasper@guideguide.com> wrote:
>
> >Steve wrote:
>
> >> sub supersort
> >> {
> >> if ($a > $b)
> >> {return -1;}
> >> if ($a < $b)
> >> {return 1;}
> >> else
> >> {return 0;}
> >> }
> >
> >Robert's Perl Tutorial seems to have rewritten the spaceship operator (
> ><=> ).
> >Or am I missing something?
>
> It's mentioned in the very next paragraph, followed by "we can
> write the above much more easily as" then some very predictable
> sample code. Guess Steve didn't get that far before venturing
> out on his own.
I was aware of the spaceship operator but i'd already written the above code
before I learned it, so I just kept it in.
Thanks for the advice people.
------------------------------
Date: Wed, 24 Oct 2001 19:23:54 +0800
From: "P" <terrie@wiredcity.com.au>
Subject: Perl and SNMP
Message-Id: <PpxB7.535$Fi4.27180@ozemail.com.au>
Hi
I have the following bit of code..
my $oid1 = '.1.3.6.1.2.1.1.5.0';
my $oid2 = '.1.3.6.1.2.1.1.8.0';
my $oid = '.1.3.6.1.2.1.1';
($session, $error) = Net::SNMP->session(
-hostname => '10.54.6.4',
-community => 'public',
-debug => '0'
);
if (!defined($userid = $session->get_table($oid))) {
printf("ERROR: is %s.\n", $session->error);
$session->close;
exit 1;
}
print "$userid->{$oid1}\n";
print "$userid->{$oid2}\n";
$session->close;
Now what I want to do is simply loop through all values that have been
assigned to $userid by the get_table function. Is there some easy way to do
this? I'm not so good on the OO stuff.
thanks
paul
btw the module is NET::SNMP
------------------------------
Date: Wed, 24 Oct 2001 18:09:14 +0800
From: "DIAMOND Mark R." <dot@dot.dot>
Subject: Regexp help needed please --- I think
Message-Id: <9r640c$ld6$1@enyo.uwa.edu.au>
I am not a frequent perl user having not really made the transition from
awk.
I use a small perl script to make corrections to the formatting of a
bibliography (translating from one format into another that is suitable for
my dissertation which is a LaTeX document). I have a problem which I can't
solve and would appreciate some help. I suspect it is a matter of getting my
brain around the correct regex. The problem is stated a paragraph of so
down. First a description of what I have. Each bibliographic entry is in a
form similar to that below. It follows the American Psychological Society
publication format.
The form of the current INPUT is as follows.
The "\item" is the first element of EVERY line. Each line represents a new
entry. There are no blank lines. Authors surnames are followed by a comma
and space and then a list of initials. Authors initials are each followed by
a period, and initials are separated by a space. If there are multiple
authors, each final initial is followed by a comma, and, in the case of the
penultimate author, is also followed by an ampersand. The list of authors is
ALWAYS followed by a parenthesised 4-digit year followed by a period.
Examples:
\item Smith, A. B. (1981).
\item Smith, A., & Jones, I. J. (1764).
\item Smith, A. B., Jones, J., & Bloggs, P. Q. R. (1971).
Problem: To pervent LaTeX using "end of sentence" spacing after the authors'
initials, and because of the LaTeX treatment of the ampersand, I need to
change the above lines to
\item Smith, A.\ B. (1981).
\item Smith, A.,~\& Jones, I.\ J. (1764).
\item Smith, A.\ B., Jones, J.,~\& Bloggs, P.\ Q.\ R. (1971).
For those who know TeX or Latex, you will see that the ~\& gives an
"unbreakable space" followed by an "escaped" ampersand. The "\ " ensures a
correct inter-word space between multiple initials, instead of the
end-of-sentence spacing that LaTeX would otherwise use. The end of sentence
spacing between the last author's last initial and the parenthesised year,
is correct. Thus no "\ ". Also, a period followed immediately by a comma, as
in the "Smith, A.\ B.," of the last example will automatically give the
correct spacing and shouldn't be changed.
I have managed the ampersand change trivially enough ,along with difficult
things (for me) like putting the correct size dash (en-dash) between page
number and em-dash between various words, dealing with German alphabets,
French accents, and so forth ... but the spacing of the initials has me
completely baffled.
I realise the chutzpah, but can anyone help?!
In case it is important, I am using
Perl, version 5.001
Unofficial patchlevel 1m.
Perl for Win32 Build 110
Built Aug 13 1996@08:18:50
--
Mark R. Diamond
Send email to psy dot uwa dot edu dot au and address to markd
http://www.psy.uwa.edu.au/user/markd
------------------------------
Date: 24 Oct 2001 10:17:09 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Regexp help needed please --- I think
Message-Id: <slrn9td4t3.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Oct 2001 18:09:14 +0800, DIAMOND Mark R. <dot@dot.dot> wrote:
> I am not a frequent perl user having not really made the transition from
> awk.
[snip]
> Examples:
>
> \item Smith, A. B. (1981).
> \item Smith, A., & Jones, I. J. (1764).
> \item Smith, A. B., Jones, J., & Bloggs, P. Q. R. (1971).
>
> Problem: To pervent LaTeX using "end of sentence" spacing after the authors'
> initials, and because of the LaTeX treatment of the ampersand, I need to
> change the above lines to
> \item Smith, A.\ B. (1981).
> \item Smith, A.,~\& Jones, I.\ J. (1764).
> \item Smith, A.\ B., Jones, J.,~\& Bloggs, P.\ Q.\ R. (1971).
>
> For those who know TeX or Latex, you will see that the ~\& gives an
> "unbreakable space" followed by an "escaped" ampersand. The "\ " ensures a
> correct inter-word space between multiple initials, instead of the
> end-of-sentence spacing that LaTeX would otherwise use. The end of sentence
> spacing between the last author's last initial and the parenthesised year,
> is correct. Thus no "\ ". Also, a period followed immediately by a comma, as
> in the "Smith, A.\ B.," of the last example will automatically give the
> correct spacing and shouldn't be changed.
[snip]
Assuming you're reading the input from filehandle <FILE>:
while (<FILE>){
s/([A-Z]\.) (?!\()/$1\\ /g;
print;
}
Cheers,
Bernard
------------------------------
Date: 24 Oct 2001 10:19:09 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Regexp help needed please --- I think
Message-Id: <slrn9td50r.3nk.bernard.el-hagin@gdndev25.lido-tech>
On 24 Oct 2001 10:17:09 GMT, Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
wrote:
>
> Assuming you're reading the input from filehandle <FILE>:
To be exact, the filehandle isn't <FILE>, it's FILE. :)
Cheers,
Bernard
------------------------------
Date: Wed, 24 Oct 2001 18:36:40 +0800
From: "DIAMOND Mark R." <dot@dot.dot>
Subject: Re: Regexp help needed please --- I think
Message-Id: <9r65jq$m2t$1@enyo.uwa.edu.au>
Pretty amazinglly marvellous.
Thank you.
mark
------------------------------
Date: Wed, 24 Oct 2001 11:42:50 GMT
From: "Geoff Clark" <gclark@wavetel.com>
Subject: Search File
Message-Id: <_OxB7.1095650$ai2.83820275@bin2.nnrp.aus1.giganews.com>
Could someone, please assit with this. What I am trying to do is create a
HTML Form that will allow users to search a file for a given result. The
Form is not below. This is just the cgi that does the searching
(hopefully). The problem that I am receiving is that it will let me search
no matter what I enter on the form it always displays the whole file. Any
suggestions would be very helpful.
Also is there a way when pushing a file into an array to have the file be
formated a different way. Example:
The Original file format is as follows:
p10020D6ACB204 00 10.1.66.13 10.1.64.2 1021903392
voicedhc
p10020D6BC31B4 00 10.1.66.14 10.1.64.2 1022592484
voicedhc
p10020D68CDA8D 00 10.1.66.15 10.1.64.2 1026616822
voicedhc
p10020D69C3B94 00 10.1.66.16 10.1.64.2 1026565757
voicedhc
The result I am looking for is as follows:
010020D6BC5991|00|10.1.66.1|10.1.64.2|1021940842|voicedhc
0100047640F5FA|00|10.1.66.2|10.1.64.2|1023213862|voicedhc
010020D6BC050C|00|10.1.66.3|10.1.64.2|1021903402|voicedhc
010020D69C22D7|00|10.1.66.4|10.1.64.2|1021401527|voicedhc
010020D6BC3A98|00|10.1.66.5|10.1.64.2|1025405219|voicedhc
Thank you,
Geoff
#!/usr/bin/perl
#Search for IP by MAC
$dhcpfile = "dhcp.db";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($mac, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$mac} = $value;
}
$searchstr = $FORM{'mac'};
open (DHCP, "dhcp.db") or dienice("Can't open dhcp.txt: $! \n");
@dhcp = <DHCP>;
close(DHCP);
print "Content-type:text/html\n\n";
print "<html><head><title>Search Results</title></head>\n";
print "<body><h3>Search Results</h3>\n";
@results = grep(/$searchstr/i,@dhcp);
$found = 0;
if ($results >= 0) {
foreach $i (@results) {
chomp($i);
($mac,$blank,$ip,$server,$lease,$name) = split(/\|/,$i);
if ($mac =~ $searchstr) {
print "$mac ($ip) - $name<br>\n";
$found = 1;
}
}
} else {
print "No results found.<p>\n";
}
if ($found == 0) {
print "No results found.<p>\n";
}
###Sub Routines Start Here###
sub dienice {
my ($msg) = @_;
print "Error\n";
print $msg;
exit;
}
------------------------------
Date: 24 Oct 2001 11:58:00 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Search File
Message-Id: <slrn9tdaq5.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Oct 2001 11:42:50 GMT, Geoff Clark <gclark@wavetel.com> wrote:
[snipped first question]
One question per thread, please.
> Also is there a way when pushing a file into an array to have the file be
> formated a different way. Example:
>
> The Original file format is as follows:
> p10020D6ACB204 00 10.1.66.13 10.1.64.2 1021903392
> voicedhc
> p10020D6BC31B4 00 10.1.66.14 10.1.64.2 1022592484
> voicedhc
> p10020D68CDA8D 00 10.1.66.15 10.1.64.2 1026616822
> voicedhc
> p10020D69C3B94 00 10.1.66.16 10.1.64.2 1026565757
> voicedhc
>
> The result I am looking for is as follows:
> 010020D6BC5991|00|10.1.66.1|10.1.64.2|1021940842|voicedhc
> 0100047640F5FA|00|10.1.66.2|10.1.64.2|1023213862|voicedhc
> 010020D6BC050C|00|10.1.66.3|10.1.64.2|1021903402|voicedhc
> 010020D69C22D7|00|10.1.66.4|10.1.64.2|1021401527|voicedhc
> 010020D6BC3A98|00|10.1.66.5|10.1.64.2|1025405219|voicedhc
If the 'voicedhc' thingy is always the same try:
------------------
#!/usr/bin/perl
use strict;
use warnings;
while(<DATA>){
next if /^voicedhc$/;
s/[^\n\S]+/|/g;
s/$/|voicedhc/;
print;
}
__DATA__
p10020D6ACB204 00 10.1.66.13 10.1.64.2 1021903392
voicedhc
p10020D6BC31B4 00 10.1.66.14 10.1.64.2 1022592484
voicedhc
p10020D68CDA8D 00 10.1.66.15 10.1.64.2 1026616822
voicedhc
p10020D69C3B94 00 10.1.66.16 10.1.64.2 1026565757
voicedhc
------------------
Cheers,
Bernard
------------------------------
Date: Wed, 24 Oct 2001 08:12:44 -0400
From: Milos Obradovic <milos.obradovic@alcatel.com>
Subject: Shareware version of pl-2-exe ?
Message-Id: <3BD6B03C.5B64DA35@alcatel.com>
I know that Perl2exe is licensed software.
Is it possible to get shareware version of a similar s/w?
Thanks,
Milos.
------------------------------
Date: 24 Oct 2001 12:25:10 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Shareware version of pl-2-exe ?
Message-Id: <slrn9tdcd2.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Oct 2001 08:12:44 -0400, Milos Obradovic
<milos.obradovic@alcatel.com> wrote:
> I know that Perl2exe is licensed software.
> Is it possible to get shareware version of a similar s/w?
s{^comp\.lang\.perl\.misc$}{http://www.google.com/search?q=perl+to+exe}
Cheers,
Bernard
------------------------------
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 1997
***************************************