[18272] in Perl-Users-Digest
Perl-Users Digest, Issue: 440 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 7 21:05:42 2001
Date: Wed, 7 Mar 2001 18:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984017113-v10-i440@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Mar 2001 Volume: 10 Number: 440
Today's topics:
Re: (Linux beginner) How to de-install and re-install P (Martien Verbruggen)
Re: (Linux beginner) How to de-install and re-install P <mischief@velma.motion.net>
Re: (Linux beginner) How to de-install and re-install P <peter.sundstrom-eds@eds.com>
Arrghh..can anyone help? :( mych@earthlink.net
Re: Arrghh..can anyone help? :( (Randal L. Schwartz)
ASP in Perl <hernux@etherac.com.ar>
Re: flock and close with empty read strangeness (Kevin Reid)
Re: Graphs in perl <terrence.brannon@oracle.com>
Re: Grokking map and grep <mischief@velma.motion.net>
Re: HELP needed: using regular expressions (regex; rege <ekliao@pacbell.net>
How to get perl not to convert decimal character <dersgniw@fuse.net>
Re: if($array1[1] eq $string1) DOESN'T WORK?? (Abigail)
Re: if($array1[1] eq $string1) DOESN'T WORK?? (Adam Moore)
Re: if($array1[1] eq $string1) DOESN'T WORK?? nobull@mail.com
Re: if($array1[1] eq $string1) DOESN'T WORK?? <peter.sundstrom-eds@eds.com>
Inside a Scalar <hernux@etherac.com.ar>
Re: Inside a Scalar <bwalton@rochester.rr.com>
Re: Inside a Scalar <maheshasolkar@yahoo.com>
Re: Inside a Scalar <uri@sysarch.com>
Re: Newbie: How do I substitute a range of lines in a <krahnj@acm.org>
Re: Perl for System V <mischief@velma.motion.net>
Re: Perl Internals <mischief@velma.motion.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Mar 2001 23:37:21 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: (Linux beginner) How to de-install and re-install Perl on Linux
Message-Id: <slrn9adhhh.nts.mgjv@verbruggen.comdyn.com.au>
On 7 Mar 2001 21:02:28 -0000,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Wed, 7 Mar 2001 22:19:14 +1100 Martien Verbruggen wrote:
>> On Tue, 6 Mar 2001 22:35:24 -0000,
>> Garry Heaton <garry@heaton6.freeserve.co.uk> wrote:
>>> I'm new to Linux/Unix and want to remove the default Perl installation, then
>>> re-install from source code because I read somewhere that the Perl libraries
>>> on some Linux distributions are incomplete. How do I remove and re-install?
>>
>> It's better to leave the original installed, otherwise all other
>> packages managed by rpm will start whinging that you don't have perl
>> installed (and that includes bind, for crying out loud!).
>>
>
> Wuss :)
Heh. Did you see what I wrote at the end?
>> I personally normally remove the default perl, and install my onw
>> package, which is just a little stub that insert those symlinks for
>> me. Most other RPMs that have dependencies on perl fall for this.
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Wed, 07 Mar 2001 23:59:48 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: (Linux beginner) How to de-install and re-install Perl on Linux
Message-Id: <tadirk535q2620@corp.supernews.com>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On 7 Mar 2001 21:02:28 -0000,
> Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>> On Wed, 7 Mar 2001 22:19:14 +1100 Martien Verbruggen wrote:
>>> On Tue, 6 Mar 2001 22:35:24 -0000,
>>> Garry Heaton <garry@heaton6.freeserve.co.uk> wrote:
>>> I personally normally remove the default perl, and install my onw
>>> package, which is just a little stub that insert those symlinks for
>>> me. Most other RPMs that have dependencies on perl fall for this.
Is this meant to prove or disprove the case for sanity? ;-)
I find all sorts of things that want perl. One of them is GNU make's
build process. Luckily, that comes in a gzipped tar file and only
checks for perl in its configuration/build, instead of looking for
packages in an RPM database.
I was wondering, though, what do you do if make wants perl and perl
wants make, and you need to install both from source? Ouch. That's
a good argument for building executables on a different box from
where they will be installed. ;-)
Has anyone reading actually had this issue come up when building
a distributionless system install?
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Thu, 8 Mar 2001 09:32:43 +1300
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: (Linux beginner) How to de-install and re-install Perl on Linux
Message-Id: <9865to$52v$1@hermes.nz.eds.com>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9ac69i.k18.mgjv@martien.heliotrope.home...
> On Tue, 6 Mar 2001 22:35:24 -0000,
> Garry Heaton <garry@heaton6.freeserve.co.uk> wrote:
> > I'm new to Linux/Unix and want to remove the default Perl installation,
then
> > re-install from source code because I read somewhere that the Perl
libraries
> > on some Linux distributions are incomplete. How do I remove and
re-install?
>
> It's better to leave the original installed, otherwise all other
> packages managed by rpm will start whinging that you don't have perl
> installed (and that includes bind, for crying out loud!).
I assume you were using your PSI::ESP module again, and realised their Linux
distribution used RPM?
------------------------------
Date: Wed, 07 Mar 2001 16:50:20 -0800
From: mych@earthlink.net
Subject: Arrghh..can anyone help? :(
Message-Id: <3oldat83lundfj229v3lhj12tkqe46j9n5@4ax.com>
Hi there,
I'm having a problem with a NT server running a PERL script. Here's my
problem:
The problem is that when you set a cookie on NT with PERL, it will
only work if you don't redirect to another place right after. If you
redirect it refuses to set the cookie.
It works fine on UNIX, but not NT.
I was able to do was narrow it down to the problem which is these two
lines of code:
print "Set-cookie: $newcookie\n";
print "Location: $websiteurl\n\n";
The first line will only work if you don't include that second line.
So, if I get rid of the second line, then the cookie sets like it
should.
But if you keep the second line in there, then the cookie refuses to
set.
I need both lines in there, and again, it work great with UNIX, but
not NT.
If anyone has used PERL script on NT, or can help me with this
problem, i would appreciate it.
Kind Regards,
Michael
------------------------------
Date: 07 Mar 2001 17:09:11 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Arrghh..can anyone help? :(
Message-Id: <m1elw9xe14.fsf@halfdome.holdit.com>
>>>>> "mych" == mych <mych@earthlink.net> writes:
mych> I was able to do was narrow it down to the problem which is these two
mych> lines of code:
mych> print "Set-cookie: $newcookie\n";
mych> print "Location: $websiteurl\n\n";
mych> The first line will only work if you don't include that second line.
mych> So, if I get rid of the second line, then the cookie sets like it
mych> should.
mych> But if you keep the second line in there, then the cookie refuses to
mych> set.
mych> I need both lines in there, and again, it work great with UNIX, but
mych> not NT.
External redirect (does $websiteurl begin with "http://your.host/what/ever")
or Internal redirect (begin with "/what/ever")?
If Internal redirect, the browser never sees it.
Another way to say it is, does the "location" on the browser change?
If not, the browser didn't see the set-cookie either.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 7 Mar 2001 21:58:59 -0300
From: "Hernux" <hernux@etherac.com.ar>
Subject: ASP in Perl
Message-Id: <986lm4$38k$1@taliesin.netcom.net.uk>
Is there a way to simulate an ASP Session Object in Perl....
Thanx
------------------------------
Date: Wed, 7 Mar 2001 20:05:56 -0500
From: kpreid@attglobal.net (Kevin Reid)
Subject: Re: flock and close with empty read strangeness
Message-Id: <1epunbr.u347udbvtpeN%kpreid@attglobal.net>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Mon, 5 Mar 2001 08:40:03 -0500,
> Kevin Reid <kpreid@attglobal.net> wrote:
> > Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >
> >> The current end-of-file can be moved around with the truncate function:
> >
> > I got bitten by this assumption once. There is some operating system (I
> > don't remember which) that doesn't change the file position after a
> > truncate(), which resulted in nulls being written to the file from the
> > truncated-to location to the current file position.
> >
> > The file was a text file, and the text editor I was using didn't show
> > nulls, so the result was a mysteriously growing file.
>
> I'd be interested to know which platform that is. I habitually precede a
> truncate with a seek to the position to truncate at (in C and Perl), and
> have been ridiculed for being overly cautious for it. My caution
> probably stems from the fact that I tend to mix Unix system calls with
> stdio, which can go terribly wrong if one's not cautious.
Hrm. This is weirder than I thought. On Mac OS, a truncate() immediately
after a print() will not function, but it will if any seek() is done
before the truncate(), even if that seek() doesn't change the position.
On Darwin (a.k.a. Mac OS X), it works as I'd expect ideally: truncation
moves the file position.
I don't have Linux here, and our emulated Windows doesn't have Perl
installed, so I can't report on either, but I've included my test
script.
Most likely, the OS that added nulls was Windows. My program that used
file truncation was running on a PC at one point in its development.
Test program results:
MacOS immediate: $VAR1 = '**********SECOND';
MacOS seek : $VAR1 = 'SECOND';
MacOS close : $VAR1 = 'SECOND';
darwin immediate: $VAR1 = '""""""""""SECOND';
darwin seek : $VAR1 = '""""""""""SECOND';
darwin close : $VAR1 = 'SECOND';
Test program:
#!/usr/bin/perl -w
use strict;
sub perform_test {
my ($doseek, $doclose) = @_;
open FH, "> truncate-test" or die $!;
print FH "*" x 10 or die $!;
open FH, "+< truncate-test" or die $!
if $doclose;
seek FH, tell(FH), 0 or die $!
if $doseek;
truncate FH, 0 or die $!;
print FH "SECOND" or die $!;
close FH or die $!;
open FH, "< truncate-test" or die $!;
use Data::Dumper;
print Dumper(<FH>);
}
print "$^O immediate: "; perform_test(0, 0);
print "$^O seek : "; perform_test(1, 0);
print "$^O close : "; perform_test(0, 1);
--
Kevin Reid: | Macintosh:
"I'm me." | Think different.
------------------------------
Date: Wed, 07 Mar 2001 15:50:19 -0800
From: Terrence Monroe Brannon <terrence.brannon@oracle.com>
Subject: Re: Graphs in perl
Message-Id: <3AA6C93B.1CDEFE00@oracle.com>
Yes. Just type GD::Graph into the search window at kobesearch.cpan.org
They aren't so great though. PLPLOT is also nice.
Raquel wrote:
> Hello
>
> How can i make a graph in perl?
>
> Thanks
>
> Raquel
--
Terrence Brannon
Oracle Corporation
500 Oracle Parkway
M/S 3op1556a
Redwood Shores, CA 94065
(650) 607-5482
------------------------------
Date: Wed, 07 Mar 2001 23:50:27 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Grokking map and grep
Message-Id: <tadia31l37t1df@corp.supernews.com>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "A" == Abigail <abigail@foad.org> writes:
> A> Chris Stith (mischief@velma.motion.net) wrote on MMDCCXLV September
> A> :} Perhaps it's the centralization of reusable implmentations with the
> A> :} author's names that reduces the need of people to label the specific
> A> :} algorithms? I can't believe that the Perl community develops
> A> :} substantially fewer new algorithms than the C or Java communities.
> A> :} There must be some social explanation. Perhaps ESR could shed some
> A> :} light on this.
> A> Well, there are the Guttman-Rosler Transform, the Orcish Maneuver
> A> and Abigails Length Horror.
> A> They are just barely "algorithms" though.
> i wouldn't classify any of them as algorithms. they are pretty much
> language specific which makes them techniques, idioms or 'transforms'.
True. I misspoke... err mistyped. Why, though, not more transforms?
Also, are there any new algorithms anyone knows about that were
introduced in Perl (or even in another language by someone active
in the Perl community)? This is the sort of thing I'm interested
in starting to document -- which language camps have done what things.
An algorithm is very impressive. A transform or idiom that's
particularly elegant, concise, efficient, or whatever is also
interesting, especially if the language in question helped
facilitate a more concise, clearer, or programming-time efficient
method of coding the same thing.
> as abigail would probably agree, a true algorithm is language
> independent. that is why knuth is useful even if he created his own
> language to express all the algorithms.
Knuth is very impressive. Some others have done specialized algorithms
which are very impressive, too. There are also new algorithms being
currently developed in the concurrent programming field and other such
advanced or specialized fields.
> but translating a given algorithm to quality/efficient code in a given
> language is not always trivial. that is where those transforms and
> idioms come in.
What really grabs my attention is the simplicity of the transform
or idiom as seen after it is implemented and published/spread/widely
accepted. Something that, like a theorem in Geometry, can be proven
step-by step until accepted, then can be used as a piece in a bigger
puzzle with only infrequent questions about why. Perl seems to have
many of these. That's one of the main reasons why most of my code
is in Perl.
Chris
--
Christopher E. Stith
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty. -- Mohandas K. Gandhi
------------------------------
Date: 7 Mar 2001 17:30:15 -0600
From: Eric Liao <ekliao@pacbell.net>
Subject: Re: HELP needed: using regular expressions (regex; regexp) or Parse::RecDescent to isolate Java/C++ statements <==== code inside, pls help :-)
Message-Id: <rbfdatg9lg81dqntq3l5eq48lhgvn82o19@4ax.com>
On 7 Mar 2001 15:29:05 -0600, Eric Liao <ekliao@pacbell.net> wrote:
Silly me. The problem associated with statements 9 and 10 are solved,
by undoing the doubling of backslashes in the regexes in grammar:
\\\\ -> \\
\\. -> \.
... etc.
I over-corrected.
So there's no problem with nesting the normal*(special(normal*)*
construct in regular expressions after all :-)
I also added the "for expression" subrule to the original grammar,
which now correctly parses statement 4.
But I still have the singlequoted character problem to solve, and this
particular issue:
The reason I used this long ugly rule:
hasdqstring : /([^"{;}\\]+)*("[^"\\]*(\\.[^"\\]*)*"([^"{;}\\]+)*)+/
instead of the more readable and Parse::RecDescent-like rules:
hasdqstring : normal(s?) (special normal(s?))(s)
normal : /[^"{;}]+/
special : /"[^"\\]*(\\.[^"\\]*)*"/
is because of my lack of experience using Parse::Recdescent. The long
ugly rule can be accessed, returned, or printed out simply as
$item[1], but I have no idea how the text matched by this rule:
normal(s?) (special normal(s?))(s)
should be returned and passed upwards to a higher-level rule for
printing. I only know that the three repetitions (including one
nested) here mean some messy dereferencing of hash variable, and I'm
not sharp enough to figure out how.
There's one demo example in the Parse::Recdescent documentation that
shows the usage of <autotree> and AUTOACTION, but it does not explain
repeated rules like above.
Any demonstration of code that prints out a parse tree would also
help.
Thanks a lot!
Eric
NEW CODE:
=================================================================
# perl version = activePerl v5.6.0 build 623
use strict;
use Parse::RecDescent;
undef $/;
my $text = @ARGV ? <> : <DATA>;
{ # start-up action
print "PRORAM:\n\n";
print "$text\n";
print "PARSE RESULTS:\n\n";
}
$::grammarRegex = <<'EOF';
program : statement(s)
statement : expression delimiter
delimiter : '{'
| '}'
| ';' '}'
| ';'
expression : forExpression
{print " for expr: $item[1]\n";}
| hasdqstring
{print "has string: $item[1]\n";}
| nodqstring
{print " no string: $item[1]\n";}
# expression cannot be empty for now
forExpression : /.*?for\s+\([^;]*(;[^;]*){2}\)/
nodqstring : /[^"{;}\\]+/
hasdqstring : /([^"{;}\\]+)*("[^"\\]*(\\.[^"\\]*)*"([^"{;}\\]+)*)+/
# this rule is equiv. to the following three but can
be accessed thru $item[1]
#hasdqstring : normal(s?) (special normal(s?))(s)
# how do i print this whole thing out?
# this follows the "unrolling the loop" technique
described in Friedl's book
#normal : /[^"{;}]+/
# the non-doublequoted-string part of a statement that
contains doublequoted strings
#special : /"[^"\\]*(\\.[^"\\]*)*"/
# a doublequoted string, allowing escaped characters (from
Friedl's book)
# this is itself another "unrolling the loop" construct:
# whole thing is "(normal)*(special(normal)*)*"
# where normal is /[^"\\]/
# and special is /\\./
EOF
my $parser = new Parse::RecDescent($::grammarRegex) or die "invalid
grammar";
defined $parser->program($text) or die "malformed program";
__DATA__
1 public class Test {
2 public static void main(String[] args) {
3 "string1" + method(args) + "string2";
4 for (init; cond; incr) {
"doThis; doThat;";
method();
}
5 concatMultilnStr = "string3" + var1
"string4";
6 "delimiters OK ; { } ; }";
7 "all esc seq OK: \" \' \n \\ \; \{ \}";
8 char needFixing = ';';
}
}
==================================================================
NEW OUTPUT
PARSE RESULTS:
no string: 1 public class Test
no string: 2 public static void main(String[] args)
has string: 3 "string1" + method(args) + "string2"
for expr: 4 for (init; cond; incr)
has string: "doThis; doThat;"
no string: method()
has string: 5 concatMultilnStr = "string3" + var1
"string4"
has string: 6 "delimiters OK ; { } ; }"
has string: 7 "all esc seq OK: \" \' \n \\ \; \{ \}"
no string: 8 char needFixing = '
no string: '
===================================================================
>expression : hasdqstring
> {print "has string: $item[1]\n";}
> | nodqstring
> {print " no string: $item[1]\n";}
>
>nodqstring : /[^"{;}\\\\]+/
>
>hasdqstring:
>/([^"{;}\\\\]+)*("[^"\\\\]*(\\\\.[^"\\\\]*)*"([^"{;}\\\\]+)*)+/
>
>ACTUAL OUTPUT
>
>PROGRAM:
>... ...
>
>PARSE RESULTS:
>
> no string: 1 public class Test
> no string: 2 public static void main(String[] args)
>has string: 3 "string1" + method(args) + "string2"
> no string: 4 for (init
> no string: cond
> no string: incr)
>has string: "doThis; doThat;"
> no string: method()
> no string: 5 char this_doesnt_work_yet = '
> no string: '
>has string: 6 concat_multiline_string = "string3" +
>var1
> "string4"
>has string: 7 "delimiters in string: OK ; { } ; }"
>has string: 8 "escaped backslash OK \\ string"
> no string: 9
>================================================================
>EXPECTED OUTPUT
>
> no string: 1 public class Test
> no string: 2 public static void main(String[] args)
>has string: 3 "string1" + method(args) + "string2"
> no string: 4 for (init; cond; incr)
>has string: "doThis; doThat;"
> no string: method()
> no string: 5 char this_doesnt_work_yet = ';'
>has string: 6 concat_multiline_string = "string3" +
>var1
> "string4"
>has string: 7 "delimiters in string: OK ; { } ; }"
>has string: 8 "escaped backslash OK \\ string"
>has string: 9 "escaped doublequote BUG \" string";
>has string: 10 "escaped anything else BUG \n string";
>================================================================
>PROBLEM DESCRIPTIONS
>
>1. Statement 4: The for loop is a known issue, since it has not been
>implemented in the grammar.
>
>2. Statement 5: I don't know how to add the rules for the following
>singlequoted characters: ';', '{', '}'. So this has not been
>implemented in the grammar either.
>
>3. For some strange reason, statements 9 and 10 are not printed out.
>I suspect it's because they contain \" and \n (actually, anything
>other than \\). I really have no idea why. Statement 8 has \\ and it
>was recognized correctly and printed. I wonder if this subtle bug is
>because I _nested_ the
>
> normal*(special(normal)*)*
>
>construct in the grammar, in the inside for matching a doublequoted
>string, and on the outside for matching an entire statement that has
>doublequoted strings.
>
>Any idea, input, suggestion?
>
>Thanks,
>Eric
>
>On 6 Mar 2001 20:05:11 -0600, Eric Liao <ekliao@pacbell.net> wrote:
>
>>Problem:
>>Given any valid Java (or c++) source code file, I need to separate it
>>into an array of statements. The delimiters used are:
>>
>> a left curly brace: /\{/
>>or a semicolon followed by a right curly brace: /;\s+\}/
>>or a semicolon: /;/
>>or a right curly brace, not preceded by a semicolon: /\}/
>>
>>A statement can be several lines, such as:
>>
>> methodA("string1" +
>> methodB + "string2");
>>
>>The difficulty is, these four delimiters can appear in the statement
>>as characters or inside doublequoted strings and should not be treated
>>as delimiters:
>>
>> char a = '}';
>> String b = "this is a semicolon => ; ";
>>
>>Also, the semicolon can appear in for loop and should not be treated
>>as delimiter:
>>
>> for (exp1; exp2; exp3) { statement(s) }
>>
>>I have tried either a regexp-only approach or a Parse::RecDescent
>>approach, but neither was error-free for me. There must be subtle
>>bugs in my code, but for a start, I'd like to ask a top-level
>>question: can a problem of such nature be solved entirely by regular
>>expressions? Which is a better approach? Does a solution already
>>exist somewhere?
>>
>>Any input is greatly appreciated. I'll follow up by posting my code
>>later.
>>
>>Thank you,
>>Eric
------------------------------
Date: Wed, 7 Mar 2001 19:00:41 -0500
From: "Brian" <dersgniw@fuse.net>
Subject: How to get perl not to convert decimal character
Message-Id: <tadjegp3o53r6f@corp.supernews.com>
I'm trying to write a CGI program that is passing around a list of | (pipe)
separated values.
ie - a|b|c
The problem is these values can contain pipes. Perl (or the webserver?)
converts the "|" to "%7C" when passed. I figured I could modify the input
values from the form so all fields that contain a | will instead contain the
decimal value.
So, received from form one, I do this:
$in{A} =~ s/%7C/|/g.
$in{B} =~ s/%7C/|/g. # I actually have quite a few of these so I
actually loop through the hash
$value = $in{A}. "|" . $in{B}
<form blah>
<input type=hidden name=allVals value=$value>
Then I pass this data along again to the next perl function.
I assume that my | will still be intact and I'll be able to simply
convert the %7C to '|' and split the values. But, it seems that the |
is converted along the way to %7C. So, all of my user inputted pipes are
intermixed with the pipes I used to join the data. I'm using | so I can
easily print the data in html.
Any ideas would be apprecated.
------------------------------
Date: 7 Mar 2001 23:24:20 GMT
From: abigail@foad.org (Abigail)
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <slrn9adgp4.q1s.abigail@tsathoggua.rlyeh.net>
Wannabe Perl Guru (donotreply@interbulletin.bogus) wrote on MMDCCXLV
September MCMXCIII in <URL:news:3AA6B1B9.56610105@interbulletin.com>:
&& I have @array1 filled with strings, and have $string1 = "somestring";
&& But when I use this statement:
&&
&& if($array1[1] eq $string1)
&& print "yes";
&&
&& Then Perl throws up!
Throws up? Do we have to guess what that means?
&& Why can't I do this this Perl?
&& What alternatives are there to the above statement??
I'm not sure what the problem is. The code, as quoted, contains a
syntax error. Is that your problem? Or do you have correct syntax
in your program, but it prints 'yes' when you don't expect it? Or
perhaps it doesn't print when you expect it to?
I'm to lazy to play the guessing game.
Abigail
--
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];
------------------------------
Date: 8 Mar 2001 00:02:43 GMT
From: adam@foo.sweet.as (Adam Moore)
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <slrn9adj6u.rv3.adam@foo.sweet.as>
>&& if($array1[1] eq $string1)
>&& print "yes";
Need {}'s after the condition.
>Throws up? Do we have to guess what that means?
[..]
>I'm to lazy to play the guessing game.
Don't put a lobster on a plate, he'll use his magnet to escape .. then he'll
bite your EYE.
>&& What alternatives are there to the above statement??
Yeah.. try:
if ( grep /^$string1$/, @array1 ) {
print "yes\n";
}
------------------------------
Date: 08 Mar 2001 00:06:49 +0000
From: nobull@mail.com
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <u9vgpljf8m.fsf@wcl-l.bham.ac.uk>
Wannabe Perl Guru <donotreply@interbulletin.bogus> writes:
> But when I use this statement:
>
> if($array1[1] eq $string1)
> print "yes";
>
> Then Perl throws up!
> Why can't I do this this Perl?
Beause the syntax of the if staement in Perl is:
if (EXPR) BLOCK
That's _block_ not _statement_.
> What alternatives are there to the above statement??
Valid Perl syntax.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 8 Mar 2001 12:27:13 +1300
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <986g4t$nov$1@hermes.nz.eds.com>
"Wannabe Perl Guru" <donotreply@interbulletin.bogus> wrote in message
news:3AA6B1B9.56610105@interbulletin.com...
> I have @array1 filled with strings, and have $string1 = "somestring";
> But when I use this statement:
>
> if($array1[1] eq $string1)
> print "yes";
>
> Then Perl throws up!
> Why can't I do this this Perl?
> What alternatives are there to the above statement??
It works fine. Try this:
#!/usr/bin/perl -w
use strict;
my @array1;
$array1[1]="somestring";
my $string1="somestring";
if ($array1[1] eq $string1) {
print "yes\n";
}
Your problem is more than likely related to your data. As you don't provide
any input, it is not possible to say where the exact problem is.
------------------------------
Date: Wed, 7 Mar 2001 21:58:12 -0300
From: "Hernux" <hernux@etherac.com.ar>
Subject: Inside a Scalar
Message-Id: <986lkm$374$1@taliesin.netcom.net.uk>
I need to know if the value of a Scalar is a string or an Integer
thanx
------------------------------
Date: Thu, 08 Mar 2001 01:29:04 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Inside a Scalar
Message-Id: <3AA6E155.B86A4D22@rochester.rr.com>
Hernux wrote:
>
> I need to know if the value of a Scalar is a string or an Integer
>
> thanx
print $Scalar=~/-?\d+/?'integer':'string';
--
Bob Walton
------------------------------
Date: Wed, 7 Mar 2001 17:36:15 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: Inside a Scalar
Message-Id: <tadoghef89d844@corp.supernews.com>
"Hernux" <hernux@etherac.com.ar> wrote in message
news:986lkm$374$1@taliesin.netcom.net.uk...
> I need to know if the value of a Scalar is a string or an Integer
You can use a scalar as string or a number. Perl decides from the context -
whether to treate it as string or number. In any case this FAQ should be
helpful.
-m.
perlfaq4 - Data Manipulation
How do I determine whether a scalar is a number/whole/integer/float?
Assuming that you don't care about IEEE notations like ``NaN'' or
``Infinity'', you probably just want to use a regular expression.
warn "has nondigits" if /\D/;
warn "not a natural number" unless /^\d+$/; # rejects -3
warn "not an integer" unless /^-?\d+$/; # rejects +3
warn "not an integer" unless /^[+-]?\d+$/;
warn "not a decimal number" unless /^-?\d+\.?\d*$/; # rejects .2
warn "not a decimal number" unless /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
warn "not a C float"
unless /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;
If you're on a POSIX system, Perl's supports the POSIX::strtod function. Its
semantics are somewhat cumbersome, so here's a getnum wrapper function for
more convenient access. This function takes a string and returns the number
it found, or undef for input that isn't a C float. The is_numeric function
is a front end to getnum if you just want to say, ``Is this a float?''
sub getnum {
use POSIX qw(strtod);
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
$! = 0;
my($num, $unparsed) = strtod($str);
if (($str eq '') || ($unparsed != 0) || $!) {
return undef;
} else {
return $num;
}
}
sub is_numeric { defined &getnum }
------------------------------
Date: Thu, 08 Mar 2001 01:59:47 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Inside a Scalar
Message-Id: <x71ys9dnqk.fsf@home.sysarch.com>
>>>>> "BW" == Bob Walton <bwalton@rochester.rr.com> writes:
BW> Hernux wrote:
>>
>> I need to know if the value of a Scalar is a string or an Integer
>>
>> thanx
BW> print $Scalar=~/-?\d+/?'integer':'string';
will that work for 'a3b'? you need to anchor that regex at both ends.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 08 Mar 2001 00:08:18 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie: How do I substitute a range of lines in a doc?
Message-Id: <3AA6CED2.FBF15B29@acm.org>
JM Wood wrote:
>
> I'd like to substitute (to update) old with new information in a document
> over a range of lines, between a specific START and END pattern.
perldoc perlop
And look for the .. operator.
John
------------------------------
Date: Wed, 07 Mar 2001 23:53:33 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl for System V
Message-Id: <tadift6mfl543@corp.supernews.com>
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Wed, 07 Mar 2001 00:07:54 -0000 Chris Stith wrote:
>> Garrett Groff <groffg@gmgdesign.com> wrote:
>>> I need to install Perl on System V. I'd like to use the source, but I
>>> downloaded one compressed source file, containing dozens upon dozens of
>>> files. Is this really going to compile??? How should I compile it? g++ *.c
>>> I'm dubious that that is going to work w/o time-consuming revisions to the
>>> source. Can anyone HELP?!
>>
>> The source distribution comes with a Makefile and an INSTALL file.
>>
> A small quibble. There is no Makefile until part way through the steps
> described in the INSTALL file.
True. Quite true. So, a configurator and an INSTALL file.
Chris
--
Christopher E. Stith
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.
------------------------------
Date: Wed, 07 Mar 2001 23:33:47 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl Internals
Message-Id: <tadharqputn71e@corp.supernews.com>
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Mon, 05 Mar 2001 20:40:59 -0000 Chris Stith wrote:
>> Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>>> On Sat, 3 Mar 2001 16:17:45 -0500 Eduard Grinvald wrote:
>>>> Hello All!!
>>>> Is there any place where i can determine how perl internally represents data
>>>> types and objects. Mostly, i need to know the level of number precision and
>>>> how many bytes do references, ints, hashes, etc take up.
>>>>
>>
>>> This kind of stuff is not documented, you will have to consult the
>>> Perl source code.
[snip]
>> For all I know, every type in Perl maps to a certain defined type
>> in C which is defined conditionally based on the platform. Somehow,
>> though, I doubt this. I'm sure some values in Perl are a different
>> size on different platforms due to mapping against C types which are
>> different on those platforms
Read just above here.
> Yeah fine, but a Perl scalar or a hash or an array *doesnt* map to a
> primitive C type - they are represented internally as structs - for instance
> an SV ( the data structure that holds a scalar ) is defined as :
> struct STRUCT_SV {
> void* sv_any; /* pointer to something */
> U32 sv_refcnt; /* how many references to us */
> U32 sv_flags; /* what we are */
> };
Now, I bet a struct would be called a "defined type". I also bet
most people would consider U32 a "defined type", and that on some
platforms U32 is an unsigned int while on others it's an unsigned
long. This would mean that these are defined types which are
defined conditionally based upon which platform you are using.
A defined type and a primitive type are not the same. You don't
define a primitive type (not in the language itself - in a grammar
of standards document maybe).
Now, sv_any is also a defined type. How big is it? Does it vary
by platform? You obviously looked deeper into the core than I
did, because you're quoting it to me. Yet, although you're looking
at it, you're no closer to your answer, and have tried to correct
me for saying something I did not say.
So, how big is sv_any? Does it vary according to the platform?
Chris
--
Christopher E. Stith
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 440
**************************************