[29174] in Perl-Users-Digest
Perl-Users Digest, Issue: 418 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 9 00:10:31 2007
Date: Tue, 8 May 2007 21: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 Tue, 8 May 2007 Volume: 11 Number: 418
Today's topics:
A question about lists <cdalten@gmail.com>
Re: A question about lists <spamtrap@dot-app.org>
Re: A question about lists <attn.steven.kuo@gmail.com>
Re: Action before clicking a link <xicheng@gmail.com>
Can not add a scalar variable of path into @INC? <Michael.Yxf@gmail.com>
Re: Can not add a scalar variable of path into @INC? <Michael.Yxf@gmail.com>
Re: Can not add a scalar variable of path into @INC? <tadmc@augustmail.com>
Re: Click link to go to routine <sykigh@trist.com>
Re: Click link to go to routine <tony_curtis32@yahoo.com>
Re: Click link to go to routine <jurgenex@hotmail.com>
Re: Click link to go to routine <sykigh@trist.com>
Re: Click link to go to routine <spamtrap@dot-app.org>
Re: Click link to go to routine <news@lawshouse.org>
Re: Click link to go to routine <rvtol+news@isolution.nl>
Re: Click link to go to routine <1usa@llenroc.ude.invalid>
Re: Click link to go to routine <tadmc@augustmail.com>
Re: Click link to go to routine <xicheng@gmail.com>
Re: Click link to go to routine <jurgenex@hotmail.com>
Converting 4 bytes to a float <Larry.Martell@gmail.com>
Re: Converting 4 bytes to a float <spamtrap@dot-app.org>
Re: How to change the comparsion criteria of diff? <Michael.Yxf@gmail.com>
Re: How to Run/Convert(?) Script Built on 5.8.4 to 5.00 <tadmc@augustmail.com>
Re: parsing a variable length record from a mixed forma (Greg Bacon)
Retrieving only the text portion of a web page <pinaki_m77@yahoo.com>
Re: Retrieving only the text portion of a web page <spamtrap@dot-app.org>
Re: Retrieving only the text portion of a web page <xicheng@gmail.com>
Re: Using an array to search a text file (Greg Bacon)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 May 2007 18:25:20 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: A question about lists
Message-Id: <1178673920.888858.224910@o5g2000hsb.googlegroups.com>
Quoting part of perldoc -f grep
"grep BLOCK LIST
grep EXPR,LIST
This is similar in spirit to, but not the same as,
grep(1) and
its relatives. In particular, it is not limited to
using regu-
lar expressions.
Evaluates the BLOCK or EXPR for each element of LIST
(locally
setting $_ to each element) and returns the list value
consist-
ing of those elements for which the expression
evaluated to
true. In scalar context, returns the number of times
the
expression was true.
@foo = grep(!/^#/, @bar); # weed out comments
or equivalently,
@foo = grep {!/^#/} @bar; # weed out comments
"
If @bar is an array, does this get converted to a list automatically?
Chad
------------------------------
Date: Tue, 08 May 2007 21:32:42 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: A question about lists
Message-Id: <m2bqgusrwl.fsf@local.wv-www.com>
grocery_stocker <cdalten@gmail.com> writes:
> If @bar is an array
What do you mean, "if"? @bar is an array. $bar is a scalar. %bar is a hash.
There's no "if" here.
> , does this get converted to a list automatically?
No conversion is needed - an array is a variable that contains a list. A
function that takes a list can handle either an array or a list literal
equally well.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 8 May 2007 18:54:10 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: A question about lists
Message-Id: <1178675650.715679.316730@l77g2000hsb.googlegroups.com>
On May 8, 6:32 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> grocery_stocker <cdal...@gmail.com> writes:
> > If @bar is an array
>
> What do you mean, "if"? @bar is an array. $bar is a scalar. %bar is a hash.
> There's no "if" here.
>
> > , does this get converted to a list automatically?
>
> No conversion is needed - an array is a variable that contains a list. A
> function that takes a list can handle either an array or a list literal
> equally well.
>
Expressions are either in scalar or list context. So, you can
even pass hashes and scalars to functions for list data
(e.g., grep, map, reverse, etc. -- see perldoc perlfun):
my $foo = 'Foo';
my @foo = qw/Foo Bar Baz Foo/;
my %foo = ( Foo => 1, Bar => 2, Baz => 'Foo');
{
local $\ = "\n";
local $, = "~>";
print grep /Foo/, $foo;
print grep /Foo/, @foo;
print grep /Foo/, %foo;
print grep /Foo/, qw/Baz Bar Foo Foo/;
}
--
Hope this helps,
Steven
------------------------------
Date: 8 May 2007 13:13:18 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Action before clicking a link
Message-Id: <1178655198.214866.288640@n59g2000hsh.googlegroups.com>
On May 8, 5:36 am, lg <l...@invalid.com> wrote:
> I have the following code (scaled down from complete code):
>
> [snip]
> print "Press link below to go to next level";
> print '<form action="http://thisandthat.com" method="post">';
> print "</form>";
> [snip]
>
> When user clicks the link he then goes to the page link point to.
> I would like to save info that the user has clicked the link.
> How do I do that?
my question:
1) There is no link, just an empty form
2) Can you use 'GET' instead of 'POST'
You might also want to check Javascript's onChange handler if you dont
like a 'submit' button
Regards,
Xicheng
------------------------------
Date: 8 May 2007 19:52:04 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Can not add a scalar variable of path into @INC?
Message-Id: <1178679124.527598.173770@q75g2000hsh.googlegroups.com>
I need to add the my lib path into @INC:
When I give the absolute path to the @INC, it works fine:
use lib "/home/michael/mylib";
But it doesn't work when I passed mylib as a scalar variable:
my $libpath = "/home/michael/mylib";
use lib $libpath;
In this way, the script can't locate the package in "mylib" path.
I need to use this scalar variable instead of hard-coded absolute
path.
Is there any ways to do this?
Thanks!
------------------------------
Date: 8 May 2007 19:56:12 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: Can not add a scalar variable of path into @INC?
Message-Id: <1178679372.406651.292430@y5g2000hsa.googlegroups.com>
On May 9, 10:52 am, Michael Yang <Michael....@gmail.com> wrote:
> I need to add the my lib path into @INC:
> When I give the absolute path to the @INC, it works fine:
> use lib "/home/michael/mylib";
> But it doesn't work when I passed mylib as a scalar variable:
> my $libpath = "/home/michael/mylib";
> use lib $libpath;
>
> In this way, the script can't locate the package in "mylib" path.
> I need to use this scalar variable instead of hard-coded absolute
> path.
> Is there any ways to do this?
> Thanks!
Seems that it doesn't work either using absolute path name.
During execution, it can not locate the *.pm file under "mylib" path.
But it works after I set the environment variable of "PERL5LIB" in the
command line.
This is not what I really need.
I want to add the lib path during the script run time.
------------------------------
Date: Tue, 8 May 2007 22:19:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can not add a scalar variable of path into @INC?
Message-Id: <slrnf42fen.bjt.tadmc@tadmc30.august.net>
Michael Yang <Michael.Yxf@gmail.com> wrote:
> But it doesn't work when I passed mylib as a scalar variable:
> my $libpath = "/home/michael/mylib";
That statement happens at run time.
> use lib $libpath;
That statement happens at compile time.
compile time comes before run time, so the "use" is evaluated
before the variable has been given a value.
Didn't you get an error message like:
Empty compile time value given to use lib at ... ?
> I need to use this scalar variable instead of hard-coded absolute
> path.
Why do you need to use this scalar variable instead of hard-coded
absolute path?
> Is there any ways to do this?
There is a way to force statements to be evaluated at compile time,
read up on the BEGIN block in perlmod.pod.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 08 May 2007 20:27:20 GMT
From: "Sykigh A Trist" <sykigh@trist.com>
Subject: Re: Click link to go to routine
Message-Id: <I250i.4801$296.819@newsread4.news.pas.earthlink.net>
>> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
>> Back</a>\n";
>
> If the routine "return_this" resides in your web server, you can wrap
> it into a CGI script or some Perl templating system files, then:
>
> print '<center><a href="/path/to/return_this.pl?name=skyhigh"
> target="_top">Go Back</a>\n';
Thanks for the replies, guys. I guess I'm not being very clear. When I say
routine I mean a subroutine that is in the same file as the print statement.
All of the code below and what I'm referring to is in the same file
(shortened for this post). When clicking this link "a
href=\"http://www.scripts.net/\" I want to change it and have it go to "sub
return_this." Hope I'm being more clear. Thanks again.
print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
Back</a>\n";
sub return_this {
my($numchoice,$ncinfile,$check,$totals,@totals,$i);
sub error {
print "Content-type: text/html","\n\n";
print "ERROR!! $_[0]";
exit;
}
sub decode_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
------------------------------
Date: Tue, 08 May 2007 16:17:24 -0400
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Click link to go to routine
Message-Id: <f1qlsm$hts$1@knot.queensu.ca>
Sykigh A Trist wrote:
> I am a complete novice at this. The code below has a link. When it is
> clicked I would like it to go to a routine called "return_this" instead
> of to the website. Can this be done within this code and does anyone
> mind showing me how to do it? Thanks.
>
> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
> Back</a>\n";
You're using the word "it" too much. This usage indicates you're
conflating a number of issues into one.
The "it" of what you see in a browser, the "it" of the URL in the link,
the "it" of the client machine, the "it" of the server machine, the "it"
of the web server receiving the request and the "it" of any external
handler (perl) that the web server might invoke as a result of receiving
an HTTP request are all completely separate things.
As a broad stroke, the client-side only makes an HTTP request, it
doesn't see implementation details on the server-side.
So you need to present a URL to the client that, under the hood, invokes
the code you want to run. SOAP might also be something to look at.
FWIW
t
------------------------------
Date: Tue, 08 May 2007 20:51:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Click link to go to routine
Message-Id: <vp50i.7239$D52.3824@trndny04>
Sykigh A Trist wrote:
> I am a complete novice at this. The code below has a link.
Ahhmmm, no. The code below has a simple print statement.
> When it is clicked
You cannot click on a print() statement.
> I would like it to go to a routine called "return_this"
> instead of to the website. Can this be done within this code and does
> anyone mind showing me how to do it? Thanks.
>
> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
> Back</a>\n";
I wonder if you maybe you meant to ask this question in a NG that deals with
web programming and/or HTML.
jue
------------------------------
Date: Tue, 08 May 2007 21:06:01 GMT
From: "Sykigh A Trist" <sykigh@trist.com>
Subject: Re: Click link to go to routine
Message-Id: <ZC50i.12985$3P3.5026@newsread3.news.pas.earthlink.net>
Hmmmm. I'm wondering why you're wondering. You're not very good at it. And
yes, the code definitely has a link. Idiot.
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:vp50i.7239$D52.3824@trndny04...
> Sykigh A Trist wrote:
>> I am a complete novice at this. The code below has a link.
>
> Ahhmmm, no. The code below has a simple print statement.
>
>> When it is clicked
>
> You cannot click on a print() statement.
>
>> I would like it to go to a routine called "return_this"
>> instead of to the website. Can this be done within this code and does
>> anyone mind showing me how to do it? Thanks.
>>
>> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
>> Back</a>\n";
>
> I wonder if you maybe you meant to ask this question in a NG that deals
> with web programming and/or HTML.
>
> jue
>
------------------------------
Date: Tue, 08 May 2007 17:57:50 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Click link to go to routine
Message-Id: <m2d51bt1up.fsf@local.wv-www.com>
"Sykigh A Trist" <sykigh@trist.com> writes:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:vp50i.7239$D52.3824@trndny04...
>>
>> I wonder if you maybe you meant to ask this question in a NG that
>> deals with web programming and/or HTML.
>
> Hmmmm. I'm wondering why you're wondering. You're not very good at it. And
> yes, the code definitely has a link. Idiot.
You've just called one of the most knowledgable and helpful members of this
group an idiot. That's not a good way to win friends and find answers...
I'd planned to answer your question, but now I think I'll wait until you've
apologized to Jürgen.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 08 May 2007 23:03:13 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Click link to go to routine
Message-Id: <1178661774.16364.0@iris.uk.clara.net>
Sykigh A Trist wrote:
> Hmmmm. I'm wondering why you're wondering. You're not very good at it. And
> yes, the code definitely has a link. Idiot.
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:vp50i.7239$D52.3824@trndny04...
>> Sykigh A Trist wrote:
>>> I am a complete novice at this. The code below has a link.
>>
>> Ahhmmm, no. The code below has a simple print statement.
>>
>>> When it is clicked
>>
>> You cannot click on a print() statement.
>>
>>> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
>>> Back</a>\n";
Not very polite; and top-posted as well, which is also impolite. Anyway
... what Jürgen meant was that the code is a print statement, with none
of the characteristics of a link, particularly the ability to click it.
That the print statement outputs code that turns into a link in an
HTML parser is not the point.
Your question is hopelessly confused. You write
> When it is clicked I would like it to go to a routine called "return_this"
The first "it" refers, presumably, to the rendered link on the browser
screen; the second "it" by contrast refers to the abstract notion of the
flow of execution - in the web server. The "routine" you refer to, on
the other hand, exists - I assume - in the Perl code which is running as
a CGI program in that server. I can only guess what you really want,
and I'm pretty sure that you don't understand how CGI programs work, and
how Perl can be used to write them, so even if I guessed correctly I
don't think you'd understand what I'd write in return.
You're simply not going to get a decent answer when you've framed your
question in such an obscure way; and that's without annoying people by
calling them idiots. Why not read the posting guidelines and try again?
--
Henry Law Manchester, England
------------------------------
Date: Wed, 9 May 2007 00:35:14 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Click link to go to routine
Message-Id: <f1r55v.19s.1@news.isolution.nl>
Xicheng Jia schreef:
> print '<center><a href="/path/to/return_this.pl?name=skyhigh"
> target="_top">Go Back</a>\n';
The \n is not a newline there. Use qq:
print qq[<center>
<a href="/path/to/return_this.pl?name=skyhigh"
target="_top">Go Back</a>\n];
or use q:
print q[<center>
<a href="/path/to/return_this.pl?name=skyhigh"
target="_top">
Go Back
</a>
];
or use a here-doc:
print <<'HTML';
<center>
<a href="/path/to/return_this.pl?name=skyhigh"
target="_top">
Go Back
</a>
HTML
(some editors will check and color-code such a HTML-bordered here-doc as
HTML)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 09 May 2007 00:00:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Click link to go to routine
Message-Id: <Xns992ACBA0F1D01asu1cornelledu@127.0.0.1>
"Sykigh A Trist" <sykigh@trist.com> wrote in
news:ZC50i.12985$3P3.5026@newsread3.news.pas.earthlink.net:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:vp50i.7239$D52.3824@trndny04...
>> Sykigh A Trist wrote:
>>> I am a complete novice at this. The code below has a link.
>>
...
>>
>> I wonder if you maybe you meant to ask this question in a NG that
>> deals with web programming and/or HTML.
> Hmmmm. I'm wondering why you're wondering. You're not very good at it.
> And yes, the code definitely has a link. Idiot.
I have been quite busy lately and I only check the group to see who needs
to be added to my killfile so I can avoid wasting time when I get back.
Thank you for making that task easier for me.
Bye.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 8 May 2007 19:59:59 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Click link to go to routine
Message-Id: <slrnf4278f.anp.tadmc@tadmc30.august.net>
Sykigh A Trist <sykigh@trist.com> wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:vp50i.7239$D52.3824@trndny04...
>> Sykigh A Trist wrote:
>>> I am a complete novice at this.
Then you probably have a lot to learn from those who are not...
>>> I would like it to go to a routine called "return_this"
>>> instead of to the website.
>> I wonder if you maybe you meant to ask this question in a NG that deals
>> with web programming and/or HTML.
>>
> I'm wondering why you're wondering.
Because Perl CGI programs run only on the "website" (webserver),
if you don't want to make a request to a webserver, then you
cannot do it with a server-side language such as Perl.
You could do it with a client-side language such as Javascript,
but this is not the Javascript newsgroup.
> You're not very good at it.
I thought you said that you were a complete novice?
You don't have enough experience to know if he's good at it or not.
And in fact, he has proven to be pretty good at helping despite
your poorly phrased question:
You do not have a Perl question. You have a Javascript question.
> yes, the code definitely has a link.
^^^?
The Perl code does not have a "link".
The HTML "code" that the Perl programs outputs has a link thingie,
but it will only be interpreted as such if the Perl programs output
ends up in a web browser...
> Idiot.
I think most people here will differ with your opinion of
who is the idiot in this thread.
So long!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 May 2007 19:29:34 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Click link to go to routine
Message-Id: <1178677774.738252.246820@y5g2000hsa.googlegroups.com>
On May 8, 4:27 pm, "Sykigh A Trist" <syk...@trist.com> wrote:
> >> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
> >> Back</a>\n";
>
> > If the routine "return_this" resides in your web server, you can wrap
> > it into a CGI script or some Perl templating system files, then:
>
> > print '<center><a href="/path/to/return_this.pl?name=skyhigh"
> > target="_top">Go Back</a>\n';
>
> Thanks for the replies, guys. I guess I'm not being very clear. When I say
> routine I mean a subroutine that is in the same file as the print statement.
> All of the code below and what I'm referring to is in the same file
> (shortened for this post). When clicking this link "a
> href=\"http://www.scripts.net/\" I want to change it and have it go to "sub
> return_this." Hope I'm being more clear. Thanks again.
> print "<center><a href=\"http://www.scripts.net/\" target=\"_top\">Go
> Back</a>\n";
>
> sub return_this {
> my($numchoice,$ncinfile,$check,$totals,@totals,$i);
>
> sub error {
> print "Content-type: text/html","\n\n";
> print "ERROR!! $_[0]";
> exit;
>
> }
>
> sub decode_form {
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
not sure if I understood you correctly, are you going to call the
script by itself??, then you probably can try the following way:
( Assume your current script name is 'myscript.pl', you can just do
some minor modifications)
1) use a query string at your link address, like:
print qq[ <center><a href="http://www.scripts.net/path/to/
myscript.pl?flag=yes" target="_top">Go Back</a> ];
2) at the beginnng(or any proper position) of your script
'myscript.pl', use whatever module method to extract the query string,
and
then check the specific query parameter 'flag', i.e.
......
my $ret = param{'flag'} || 'no'; #
if ( $ret eq 'yes' ) {
return_this(.........);
} else {
# do your normal stuff
print qq[ <center><a href="http://www.scripts.net/path/to/
myscript.pl?flag=yes" target="_top">Go Back</a> ];
# do more stuff
}
Just some logics, you may need to figure a way to do it by yourself.
Regards,,
Xicheng
------------------------------
Date: Wed, 09 May 2007 04:00:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Click link to go to routine
Message-Id: <qHb0i.3944$rk5.491@trndny06>
[Please do not top-post full-quote. Trying to fix]
[Do not stealth-CC me. I happen to read the NGs I'm posting to]
Sykigh A Trist wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:vp50i.7239$D52.3824@trndny04...
>> Sykigh A Trist wrote:
>>> print "<center><a href=\"http://www.scripts.net/\"
>>> target=\"_top\">Go Back</a>\n";
>>
>> I wonder if you maybe you meant to ask this question in a NG that
>> deals with web programming and/or HTML.
> Hmmmm. I'm wondering why you're wondering. You're not very good at
> it. And yes, the code definitely has a link. Idiot.
The code you presented above consists of a single print() statement and some
data. As far as Perl/perl is concerned that data could be the first verse of
"God save the Queen" or the incantations of Buddha. It is still plain old
data and Perl does not care what kind of data.
The fact, that this data in some context may be interpreted as HTML code is
irrelevant to Perl. So no, there is no link in your Perl code.
Now, having said that, why am I so anal about this? Very simple. Recognizing
and dividing a problem into the right problem domains is an essential skill
for any software engineer. Your question/problem has nothing to do with
Perl. It would still be exactly the same problem with exactly the same
answer if you would be using a C "printf()" or a Modula "writeln()". In
other words: you are barking up the wrong tree. Try the HTML tree or the web
programming tree instead.
jue
------------------------------
Date: 8 May 2007 17:35:25 -0700
From: "Larry.Martell@gmail.com" <Larry.Martell@gmail.com>
Subject: Converting 4 bytes to a float
Message-Id: <1178670925.774345.76730@e51g2000hsg.googlegroups.com>
I have a situation where I have to read in 4 values from a text file,
then convert that into a float that I can use for arithmetic.
For example, the file contains "85,170,174,214" - I read this in, and
split it into an array, @d
In C, I would do something akin to this:
union convert_float32 {
float f; // float view
unsigned int i; // uint32 view
} c;
unsigned char i[4];
char *q;
for (int j=0; j<4; j++) i[j] = (unsigned char)strtoul(d[j], &q, 10);
c.i = ((unsigned int)i[0] << 24) | ((unsigned int)i[1] << 16) |
((unsigned int)i[2] << 8) | (unsigned int)i[3];
and c.f would have the value I want (in this example
23458486419456.000000)
Is there some way I can achieve the result with perl?
TIA!
-larry
How can I do a similar conversion in perl?
------------------------------
Date: Tue, 08 May 2007 21:25:06 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Converting 4 bytes to a float
Message-Id: <m2fy66ss99.fsf@local.wv-www.com>
"Larry.Martell@gmail.com" <Larry.Martell@gmail.com> writes:
> I have a situation where I have to read in 4 values from a text file,
> then convert that into a float that I can use for arithmetic.
>
> For example, the file contains "85,170,174,214" - I read this in, and
> split it into an array, @d
That's 14 bytes, not counting the quotes. Are you reading a text string
of four numbers separated by commas, or are you reading four bytes?
> In C, I would do something akin to this:
>
> union convert_float32 {
> float f; // float view
> unsigned int i; // uint32 view
> } c;
> unsigned char i[4];
> char *q;
>
> for (int j=0; j<4; j++) i[j] = (unsigned char)strtoul(d[j], &q, 10);
> c.i = ((unsigned int)i[0] << 24) | ((unsigned int)i[1] << 16) |
> ((unsigned int)i[2] << 8) | (unsigned int)i[3];
>
> and c.f would have the value I want (in this example
> 23458486419456.000000)
>
> Is there some way I can achieve the result with perl?
Well, assuming you want the *correct* result, not the one you get from
the incorrect use of a union above, and assuming you have the string
from above (not four bytes):
#!/usr/bin/perl
use strict;
use warnings;
my $numbers_line = <>;
print "Numbers = $numbers_line";
chomp $numbers_line;
my @numbers = split /,/, $numbers_line;
my $total = ($numbers[0] << 24) + ($numbers[1] << 16) +
($numbers[2] << 8) + $numbers[3];
print "Total = $total\n";
This prints:
Numbers = 85,170,174,214
Total = 1437249238
Why does print a different number? Because accessing c.f in the above C
does not convert c.i to a float. A union uses the same memory for all of
its members unchanged, treating that memory as if it were *already* of
the appropriate type being accessed.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 8 May 2007 19:02:33 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: How to change the comparsion criteria of diff?
Message-Id: <1178676153.568634.256520@h2g2000hsg.googlegroups.com>
On May 8, 2:47 pm, Michael Yang <Michael....@gmail.com> wrote:
> On May 8, 11:18 am, Michael <Michael....@gmail.com> wrote:
>
>
>
> > Hi all:
> > I'm meeting the problem with diff methods in Perl.
> > I am comparing two files, one containing regular-expression string
> > texts, and the other doesn't. what I need to do is to find the
> > difference between EXCEPT FOR when regular expression matches with the
> > other's corresponding text, which is shown as below,
> > For example:
> > A.txt: Hello every one! I like .* languages very much!
> > B.txt: Hello every one! I like Perl Languages very much!
> > The regexp ".*" in A.txt is used to match any string in B.txt as the
> > normal regular expression does. Here A.txt and B.txt are considered
> > equal. But the general diff method would consider them as difference
> > with line-by-line text comparison. And if there are different, I want
> > the output with same behavior as in the UNIX.
>
> > I searched into the modules of Perl, like Text::Diff, Algorithm::Diff,
> > but didn't get any idea of it. I saw that one comparison method can be
> > passed into Algorithm::Diff as the new comparison criteria in the doc
> > online, but failed after trying. Could any one give a simple example
> > showing this feature?
> > my (@seq1, @seq2) = (<FH1>, <FH2>);
> > diff(\@seq1, \@seq2, $comparison_function);
> > I don't know what is the rules of designing this $comparison_function?
>
> > If there is some other way to do this, please kindly tell me, thanks
> > very much!
>
> To be more clearly on this question:
> I need the script to ignore the text differences when the regex in one
> file matches the corresponding part in the other. Thus I need to ask
> the diff utility to compare two files with the new rules of regex as
> shown above, which could be defined in a comparison function by user
> self.
Is there anyone could help me on this diff implementation?
It's really appreciated.
------------------------------
Date: Tue, 8 May 2007 20:10:48 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to Run/Convert(?) Script Built on 5.8.4 to 5.004
Message-Id: <slrnf427so.anp.tadmc@tadmc30.august.net>
foolishbrat <ewijaya@gmail.com> wrote:
> I have several Perl scripts which was written under Perl version
> 5.8.4.
> Now I need to run them on a office server where Perl 5.004 was
> installed.
That version of perl was released in 1997 or 1998.
A whole lot can happen in a decade...
> (And I have no option to install Perl interpreter on my home
> directory).
Why not?
Because Perl costs so much?
Company policy?
Some other obstacle?
> Is there a way I can convert/run my code such that it can be
> executed on environment where Perl 5.004 is installed?
Yes.
1) run your 5.8.4 program on a 5.004 interpreter.
2) observe what breaks
3) fix those things that you have observed
You might also consider seeing the perl*delta.pod files in the 70 or so
perl releases that have occurred between 5.004 and 5.8.4.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 08 May 2007 20:32:44 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: parsing a variable length record from a mixed format file
Message-Id: <1341njceth4knbc@corp.supernews.com>
In article <1178645783.296178.81720@e51g2000hsg.googlegroups.com>,
<chadmay@hotmail.com> wrote:
: You are correct, those are literal TABS that I've specificly listed in
: the record layout. Since I'm somewhat of a PERL newbie, I want to make
: sure I'm not missing anything. Where would I insert the line you
: proposed and what other changes to my current code, do I need to make?
John W. Krahn's followup seems to have a reasonable approach.
Has it made it to your news server? Does it help?
Greg
--
Every kind of peaceful cooperation among men is primarily based on
mutual trust and only secondarily on institutions such as courts of
justice and police.
-- Albert Einstein
------------------------------
Date: 8 May 2007 19:18:57 -0700
From: googler <pinaki_m77@yahoo.com>
Subject: Retrieving only the text portion of a web page
Message-Id: <1178677137.519248.109160@q75g2000hsh.googlegroups.com>
I want to get the content of specific web pages and do some processing
on them. I found that the LWP class can help with the first part. I
have never used LWP before and found some simple code like the one
below that returns a web page content.
my $url = 'http://www.yahoo.com';
use LWP::Simple;
my $content = get $url;
I am interested in only the text part of the web page (that is,
without any tags, cross links etc). Is there an easy way to get this
(without having to search through the entire content and filtering out
the part that I don't need)?
------------------------------
Date: Tue, 08 May 2007 22:34:39 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Retrieving only the text portion of a web page
Message-Id: <m2wsziragw.fsf@local.wv-www.com>
googler <pinaki_m77@yahoo.com> writes:
> I am interested in only the text part of the web page (that is,
> without any tags, cross links etc). Is there an easy way to get this
This is a Frequently Asked Question:
perldoc -q html
Found in /System/Library/Perl/5.8.6/pods/perlfaq9.pod
How do I remove HTML from a string?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 8 May 2007 19:37:50 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Retrieving only the text portion of a web page
Message-Id: <1178678270.942936.219930@n59g2000hsh.googlegroups.com>
On May 8, 10:18 pm, googler <pinaki_...@yahoo.com> wrote:
> I want to get the content of specific web pages and do some processing
> on them. I found that the LWP class can help with the first part. I
> have never used LWP before and found some simple code like the one
> below that returns a web page content.
>
> my $url = 'http://www.yahoo.com';
> use LWP::Simple;
> my $content = get $url;
>
> I am interested in only the text part of the web page (that is,
> without any tags, cross links etc). Is there an easy way to get this
> (without having to search through the entire content and filtering out
> the part that I don't need)?
You dont have to go with Perl, if you are under linux-box and have
lynx, then:
lynx -dump -nolist http://www.yahoo.com
(you can certainly try a Win32 version lynx)
Regards,
Xicheng
------------------------------
Date: Tue, 08 May 2007 20:26:51 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Using an array to search a text file
Message-Id: <1341n8bp7c430fd@corp.supernews.com>
In article <1178643648.388202.252460@e51g2000hsg.googlegroups.com>,
Robert Hicks <sigzero@gmail.com> wrote:
: Mine doesn't complete using the second version. Is anything loading
: into memory? The log file the while statement would be reading is
: pretty big.
In case I wasn't clear, my earlier followup contained three
separate programs to give you an idea of the test inputs I used.
The scanner, the last program, reads the log file one line at a
time, so you should see progress proportional to the hit density
in the log while it's chugging. Are you seeing any output at all?
How many lines are in the id file?
Greg
--
Whenever the legislators endeavor to take away and destroy the property of
the people, or to reduce them to slavery under arbitrary power, they put
themselves into a state of war with the people, who are thereupon absolved
from any further obedience . . . -- John Locke
------------------------------
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 418
**************************************