[23709] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5915 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 9 09:05:48 2003

Date: Tue, 9 Dec 2003 06:05:12 -0800 (PST)
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, 9 Dec 2003     Volume: 10 Number: 5915

Today's topics:
    Re: #!/usr/bin/perl <dave.nospam@ntlworld.com>
    Re: #!/usr/bin/perl <GlgAs@netscape.net>
    Re: #!/usr/bin/perl <matthew.garrish@sympatico.ca>
        Getting array indices matching some criterion <bazell@comcast.net>
    Re: Getting array indices matching some criterion (Anno Siegel)
    Re: Getting array indices matching some criterion <REMOVEsdnCAPS@comcast.net>
    Re: Getting array indices matching some criterion (Anno Siegel)
    Re: Getting return code from a child process (Anno Siegel)
    Re: Help with formatting output with Text::Table <mothra@nowhereatall.com>
    Re: Help with formatting output with Text::Table <mothra@nowhereatall.com>
        Rounding up to 2 decimal places <gary@abertron.co.uk>
    Re: Rounding up to 2 decimal places (Anno Siegel)
    Re: Rounding up to 2 decimal places <REMOVEsdnCAPS@comcast.net>
    Re: Rounding up to 2 decimal places <gary@tgpmakers.com>
    Re: Scp files to another server help <vladimir@NoSpamPLZ.net>
    Re: string matching question. (Anno Siegel)
        Why does ne always work <gary@tgpmakers.com>
    Re: Why does ne always work (Anno Siegel)
    Re: Why does ne always work <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Why does ne always work <gary@tgpmakers.com>
    Re: Why does ne always work (Anno Siegel)
    Re: Why does ne always work <jurgenex@hotmail.com>
    Re: Why does ne not always work i meant <gary@tgpmakers.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 09 Dec 2003 11:10:50 +0000 (GMT)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: #!/usr/bin/perl
Message-Id: <qnirfnivyyragyjbeyqpbz.hpmya21.pminews@text.news.ntlworld.com>

On Tue, 9 Dec 2003 10:37:02 +0200, Roman Khutkyy wrote:

>Hi all,
>is there any ability in Perl to write the first string in script as
>alternative string for different platforms.
>I write CGI scripts on the Win32 computer, then I transport it to the Unix
>server, and each time i need to rewrite this string. Is there universal
>string for both platforms?
>

One way is to use perl <command> on one platform and <command> on the
other. If you use the former and also have a shebang line perl will
obey the switches on it but not try and find the executable. At least
this is true for the 5.8.0 OS/2 port.


Regards

Dave Saville

NB switch saville for nospam in address




------------------------------

Date: Tue, 09 Dec 2003 12:53:13 GMT
From: gilgames <GlgAs@netscape.net>
Subject: Re: #!/usr/bin/perl
Message-Id: <ZAjBb.10425$aw2.5224111@newssrv26.news.prodigy.com>

<<
Hi all,
is there any ability in Perl to write the first string in script as
alternative string for different platforms.
I write CGI scripts on the Win32 computer, then I transport it to the Unix
server, and each time i need to rewrite this string. Is there universal
string for both platforms?
 >.

My expreience is that the ActiveState WIN32 plattform runs w/o any or 
with incorrect  #!/usr/bin/perl line, supposed it is crrectly ibstalled. 
So set the first string required by the Unix server.



------------------------------

Date: Tue, 9 Dec 2003 08:15:51 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: #!/usr/bin/perl
Message-Id: <7WjBb.394$tk1.178887@news20.bellglobal.com>


"Karlheinz Weindl" <karlheinz.weindl@oooonlinehome.de> wrote in message
news:br47ko$4ok$1@online.de...
> ko schrieb:
> >
> > If you're using Active State Perl you can keep the shebang line intact -
> > its ignored, [...]
>
> Not necessarily true. The OP transfers CGI scripts from Win32 to UNIX,
> so presumably running Apache under Windows, which in turn requires the
> shebang line to be present (and correct of course).
>

That's not entirely true either. You can specify to use the registry in your
Apache config file on Windows, and then just keep the shebang line for the
Unix system.

Matt




------------------------------

Date: Tue, 9 Dec 2003 06:28:15 -0500
From: "Dave Bazell" <bazell@comcast.net>
Subject: Getting array indices matching some criterion
Message-Id: <wbqdncYiGZxQLEiiRVn-vg@comcast.com>

I was wondering if there is a more general way to do the following, shown in
the code below?  I am trying to find the indices of an array that match a
certain criterion.  I would like to make a subroutine tht does this, where I
can replace the expression in the if() with an arbitrary expression.

Perhaps there is a more clever way to do this with grep or map or something?

Thanks,

Dave



#!/usr/bin/perl -w -d

@temp = (1,2,1,4,3,2,1,2,3,1);

$iclass  = 1;

for ($j=0; $j<@temp; $j++) {
    if ($temp[$j] == $iclass) {
    push (@tmp, $j);
    }
}
print "elem idx= @tmp\n";






------------------------------

Date: 9 Dec 2003 11:39:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting array indices matching some criterion
Message-Id: <br4c9m$mbq$2@mamenchi.zrz.TU-Berlin.DE>

Dave Bazell <bazell@comcast.net> wrote in comp.lang.perl.misc:
> I was wondering if there is a more general way to do the following, shown in
> the code below?  I am trying to find the indices of an array that match a
> certain criterion.

That's what grep() is for.

>                     I would like to make a subroutine tht does this, where I
> can replace the expression in the if() with an arbitrary expression.
> 
> Perhaps there is a more clever way to do this with grep or map or something?

Well, yes.  Grep.

> #!/usr/bin/perl -w -d

No warnings, no strict, no lexicals.  Substandard.

> @temp = (1,2,1,4,3,2,1,2,3,1);
> 
> $iclass  = 1;
> 
> for ($j=0; $j<@temp; $j++) {
>     if ($temp[$j] == $iclass) {
>     push (@tmp, $j);
>     }
> }
> print "elem idx= @tmp\n";


Untested:

    my @tmp = grep $temp[ $_] == $iclass, 0 .. $#temp;

Anno


------------------------------

Date: Tue, 09 Dec 2003 06:50:27 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Getting array indices matching some criterion
Message-Id: <Xns944C500634E0Esdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Dave Bazell" <bazell@comcast.net> wrote in
news:wbqdncYiGZxQLEiiRVn-vg@comcast.com: 

> I was wondering if there is a more general way to do the following,
> shown in the code below?  I am trying to find the indices of an array
> that match a certain criterion.  I would like to make a subroutine tht
> does this, where I can replace the expression in the if() with an
> arbitrary expression. 

Here's one from my library:

=item indexes_where

 @list = indexes_where {code} @list;

Returns a list of the indexes into C<@list> of the values that satisfy
the given condition.  Sort of like C<grep>, but returns index
positions instead of values.  Each element is passed to C<{code}> as
C<$_>. (as an lvalue alias, like for C<grep>).  Returns the empty list
if no value in the list satisfies the condition.

Example:

     @x = indexes_where {$_ > 5}  (4..9);    # returns (2, 3, 4, 5)
     @x = indexes_where {$_ > 5}  (1..4);    # returns ()

=cut

#--->     @list = indexes_where {code} @list;
#
# Change History:
#     06/11/2002  EJR  First version
sub indexes_where (&@)
{
    my $test = shift;
    local $_;
    my $ix=0;
    my @ixs=();
    foreach (@_)
    {
        push @ixs, $ix if $test->();
        $ix++;
    }
    return @ixs;
}


> #!/usr/bin/perl -w -d
> 
> @temp = (1,2,1,4,3,2,1,2,3,1);
> 
> $iclass  = 1;
> 
> for ($j=0; $j<@temp; $j++) {
>     if ($temp[$j] == $iclass) {
>     push (@tmp, $j);
>     }
> }
> print "elem idx= @tmp\n";


@tmp = indexes_where {$_ == $iclass} @temp;

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE/1cVoY96i4h5M0egRAnOdAJ9/OV7GUMPuGZo10b+l0jelZ5K8mgCg7GH/
qA+57/M82QVEn54wD4iT6OE=
=E5hX
-----END PGP SIGNATURE-----


------------------------------

Date: 9 Dec 2003 13:39:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting array indices matching some criterion
Message-Id: <br4jb2$mbq$7@mamenchi.zrz.TU-Berlin.DE>

Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote in comp.lang.perl.misc:

[...]

> #--->     @list = indexes_where {code} @list;
> #
> # Change History:

YOU CAN'T CHANGE HISTORY

> #     06/11/2002  EJR  First version
> sub indexes_where (&@)
> {
>     my $test = shift;
>     local $_;
>     my $ix=0;
>     my @ixs=();
>     foreach (@_)
>     {
>         push @ixs, $ix if $test->();
>         $ix++;
>     }
>     return @ixs;
> }

Grep can still do the job, if you don't mind a little obscurity:

    sub indexes_where_b (&@) {
        my $test = shift;
        grep { local $_ = $_[ $_]; $test->() } 0 .. $#_;
    }

Bonus question:  Why is "local" necessary and what happens without it?

Anno


------------------------------

Date: 9 Dec 2003 11:34:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting return code from a child process
Message-Id: <br4bvf$mbq$1@mamenchi.zrz.TU-Berlin.DE>

Jim Gibson  <jgibson@mail.arc.nasa.gov> wrote in comp.lang.perl.misc:
> In article <bqqlnp$mpn$1@wisteria.csv.warwick.ac.uk>, Ben Morrow
> <usenet@morrow.me.uk> wrote:
> 
> [question from Jon about getting return code from child process snipped]
> 
> > 
> > > I *think* there might be a way to do this with pipes, but
> > > I have no clue as to how to do that.
> > 
> > 2. Pass the data back from child to parent in a pipe. You need to
> >    decide on some format for your data: if there are no other
> >    considerations, Storable provides a compact representation of
> >    'most any Perl data structure. The way you would do this would be
> >    something like (this is completely untested and written straight
> >    off the top of my head):
> > 
> > use Storable qw/store_fd fd_retrieve/;
> > 
> > my $kid = fork;
> > defined $kid or die "fork failed: $!";
> > 
> > pipe my $FROM, my $TO;
> > 
> > if($kid) {
> >     close $TO;
> >     # parent
> > } else {
> >     close $FROM;
> >     my $return = my_function();
> >     store_fd \$return, $TO; # you have to store a reference
> >     exit 0;
> > }
> > 
> > my $return = fd_retrieve $FROM or die "fd_retrieve: $!";
> > $return = $$return; # de-ref the reference
> > close $FROM;
> > 
> 
> While I am loathe to question the answers of others, shouldn't one

You must be new around here :)

> create the pipe _before_ doing the fork so that both parent and child
> process are using the same anonymous pipe?

Correct.  The way it is, parent and kid each open their own pipe,
which have nothing to do with each other.  Thus fd_retrieve complains
in the parent when the pipe returns nothing.

Moving "pipe" three lines up fixes that.

Correcting erroneous answers is a public service, and no regular will
take offense.  That goes for all technical newsgroups.  It is comforting
to know that code that passes through the group is thoroughly scrutinized.

Anno


------------------------------

Date: Tue, 9 Dec 2003 05:38:44 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Help with formatting output with Text::Table
Message-Id: <3fd5c347$1@usenet.ugs.com>

Hi Gunnar,

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:br30ol$257vkv$1@ID-184292.news.uni-berlin.de...
> Mothra wrote:
> > I need some help formatting text output using Text table. Is there
> > a way to increase the space between the columns? The output from
> > what I have is:

[snipped]

> How about doing as the documentation for Text::Table suggests? ;-)

I guess I missed that :(

>
>      my $tb = Text::Table->new(
>          { title => 'Date', align_title => 'center' },
>          { is_sep => 1, title => '        ' },
>          { title => 'Sunset Time', align_title => 'center' }
>      );
yep! That works great :)
Thanks

Mothra





------------------------------

Date: Tue, 9 Dec 2003 05:40:37 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Help with formatting output with Text::Table
Message-Id: <3fd5c3b8$1@usenet.ugs.com>

Hi Keith,

"ko" <kuujinbo@hotmail.com> wrote in message
news:92d64088.0312081715.1a9c08a0@posting.google.com...
> "Mothra" <mothra@nowhereatall.com> wrote in message
news:<3fd48d94@usenet.ugs.com>...
> > Hi All,
> >
> > I need some help formatting text output using Text table.
> > Is there a way to increase the space between the columns?
> > The output from what I have is:

[more snippage]

> [snip code]
>
> There probably is a better way to do this, since the following code
> uses two tables to align the 'overall title':

This works great :)
Thanks !

Mothra





------------------------------

Date: Tue, 09 Dec 2003 12:26:35 +0000
From: Gary Mayor <gary@abertron.co.uk>
Subject: Rounding up to 2 decimal places
Message-Id: <br4etq$nd8$1@newsg1.svr.pol.co.uk>

Hi,
What a nightmare i've been trawling deja all morning for a simple method 
of rounding a number up to 2 decimal places. I've checked out the ceil 
function which only rounds numbers up to no decimal places which is no 
good. The printf function rounds numbers up and down.

Let's take this number

0.3325

I need it to be,

0.34

How do i do that. Do I have to write a routine that checks if there is a 
third digit or what. The number is calculated for the UK VAT system at 
17.5% i need the number rounded up to only 2 decimal places. Yes I have 
checked perlfaq4.

Simple problem seems impossible answer.

Any ideas

Gary



------------------------------

Date: 9 Dec 2003 12:49:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Rounding up to 2 decimal places
Message-Id: <br4gd2$mbq$5@mamenchi.zrz.TU-Berlin.DE>

Gary Mayor  <gary@abertron.co.uk> wrote in comp.lang.perl.misc:
> Hi,
> What a nightmare i've been trawling deja all morning for a simple method 
> of rounding a number up to 2 decimal places. I've checked out the ceil 
> function which only rounds numbers up to no decimal places which is no 
> good.

Then help it along.

>        The printf function rounds numbers up and down.
>
> Let's take this number
> 
> 0.3325
> 
> I need it to be,
> 
> 0.34
> 
> How do i do that. Do I have to write a routine that checks if there is a 
> third digit or what. The number is calculated for the UK VAT system at 
> 17.5% i need the number rounded up to only 2 decimal places. Yes I have 
> checked perlfaq4.

Financial calculations are best done in the smallest unit of currency.
Multiply by 100 on input, divide by 100 on output.  That would make
the problem with ceil() go away, because you only *have* integers.

> Simple problem seems impossible answer.

    ceil( 100*$x)/100

Oh, and you could put question marks after your questions.  You sound
over-assertive without them :)

Anno


------------------------------

Date: Tue, 09 Dec 2003 06:51:42 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Rounding up to 2 decimal places
Message-Id: <Xns944C503C7AB5Fsdn.comcast@216.196.97.136>

Gary Mayor <gary@abertron.co.uk> wrote in news:br4etq$nd8$1
@newsg1.svr.pol.co.uk:

> Hi,
> What a nightmare i've been trawling deja all morning for a simple method 
> of rounding a number up to 2 decimal places. I've checked out the ceil 
> function which only rounds numbers up to no decimal places which is no 
> good. The printf function rounds numbers up and down.
> 
> Let's take this number
> 
> 0.3325
> 
> I need it to be,
> 
> 0.34
> 
> How do i do that. Do I have to write a routine that checks if there is a 
> third digit or what. The number is calculated for the UK VAT system at 
> 17.5% i need the number rounded up to only 2 decimal places. Yes I have 
> checked perlfaq4.
> 
> Simple problem seems impossible answer.

Multiply by 100, ceil, divide by 100?  That's the first thing that occurs 
to me.


-- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print


------------------------------

Date: Tue, 09 Dec 2003 12:58:15 +0000
From: Gary Mayor <gary@tgpmakers.com>
Subject: Re: Rounding up to 2 decimal places
Message-Id: <br4gp4$3en$1@newsg4.svr.pol.co.uk>

You total star. I was never good at maths anyway. That works a treat. I 
don't put question marks after questions because on a few occasions i've 
been told question marks look to something or another. So what do I do 
with or without question marks mmmmm looks like it depends where i am.

Thank you very much

Gary


Anno Siegel wrote:
> Gary Mayor  <gary@abertron.co.uk> wrote in comp.lang.perl.misc:
> 
>>Hi,
>>What a nightmare i've been trawling deja all morning for a simple method 
>>of rounding a number up to 2 decimal places. I've checked out the ceil 
>>function which only rounds numbers up to no decimal places which is no 
>>good.
> 
> 
> Then help it along.
> 
> 
>>       The printf function rounds numbers up and down.
>>
>>Let's take this number
>>
>>0.3325
>>
>>I need it to be,
>>
>>0.34
>>
>>How do i do that. Do I have to write a routine that checks if there is a 
>>third digit or what. The number is calculated for the UK VAT system at 
>>17.5% i need the number rounded up to only 2 decimal places. Yes I have 
>>checked perlfaq4.
> 
> 
> Financial calculations are best done in the smallest unit of currency.
> Multiply by 100 on input, divide by 100 on output.  That would make
> the problem with ceil() go away, because you only *have* integers.
> 
> 
>>Simple problem seems impossible answer.
> 
> 
>     ceil( 100*$x)/100
> 
> Oh, and you could put question marks after your questions.  You sound
> over-assertive without them :)
> 
> Anno



------------------------------

Date: Tue, 09 Dec 2003 13:23:21 GMT
From: lostriver <vladimir@NoSpamPLZ.net>
Subject: Re: Scp files to another server help
Message-Id: <d1kBb.66244$pQ1.1555321@wagner.videotron.net>

On Tue, 09 Dec 2003 10:16:25 +0000, Jim Mozley wrote:
> JennAshton wrote:
>
>
>> I wrote a simple scp script from my server to pacman server which
>> copies all jpg files to /jennash/ directory.
>
> This answer is not perl related directly, but I moved from using scp to 
> rsync for this type of thing. The perl bit is that once files were 
> transferred I then needed to do other tasks (e.g. sighup a daemon) so I 
> used the perl script which did the rsync to perform other tasks.
>
> Jim

Try Net::SFTP. Gives you whole lot more of control - you can verify sizes
after transfer of each file, set timeouts for login and per file transfer, etc



-- 
 .signature: No such file or directory


------------------------------

Date: 9 Dec 2003 14:04:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string matching question.
Message-Id: <br4kpq$shv$1@mamenchi.zrz.TU-Berlin.DE>

Eric Schwartz  <emschwar@pobox.com> wrote in comp.lang.perl.misc:
> mishq00@yahoo.com (Mohammed Ishaq) writes:
> > I have a been trying to do a string match, and the string has []
> > characters. I do not want perl to treat this a regular expression, but
> > I cannot get it match. I have the following perl snippet, and the
> > output of these two searches is different, but I think that both
> > searches should match successfully.
> 
> If you want to match a literal substring, then you don't want a regex,
> you want index():
> 
> my $e="abcde[12]"; 
> my $f="XYZ[12] abcde[12] XYZ[12]";
> print "$e is in $f\n" if (index($f, $e));

    print "$e is in $f\n" if 1 + index($f, $e);

Anno


------------------------------

Date: Tue, 09 Dec 2003 12:31:44 +0000
From: Gary Mayor <gary@tgpmakers.com>
Subject: Why does ne always work
Message-Id: <br4f7d$q6s$1@news6.svr.pol.co.uk>

Hi,
Whilst i'm here i might as well see if anyone else has noticed strange 
things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
I always end up doing it a different way as i start pulling my hair out 
because everything is correct it just doesn't work.

Anyone else had that problem.

Gary



------------------------------

Date: 9 Dec 2003 12:35:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why does ne always work
Message-Id: <br4fj2$mbq$4@mamenchi.zrz.TU-Berlin.DE>

Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
> Hi,
> Whilst i'm here i might as well see if anyone else has noticed strange 
> things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 

Would you please explain what you mean by "doesn't work". "$blah ne
$blah" will always return false.  It may also issue a warning if
$blah is undefined.

> I always end up doing it a different way as i start pulling my hair out 
> because everything is correct it just doesn't work.
> 
> Anyone else had that problem.

What problem?

Anno


------------------------------

Date: Tue, 9 Dec 2003 12:45:39 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Why does ne always work
Message-Id: <Xns944C8BA5EF390elhber1lidotechnet@62.89.127.66>

Gary Mayor <gary@tgpmakers.com> wrote:

> Hi,
> Whilst i'm here i might as well see if anyone else has noticed strange 
> things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
> I always end up doing it a different way as i start pulling my hair out 
> because everything is correct it just doesn't work.
> 
> Anyone else had that problem.


Hell yes. I have it all the time.


-- 
Cheers,
Bernard


------------------------------

Date: Tue, 09 Dec 2003 12:52:08 +0000
From: Gary Mayor <gary@tgpmakers.com>
Subject: Re: Why does ne always work
Message-Id: <br4gdl$o0u$1@newsg1.svr.pol.co.uk>

That's what i mean $blah ne $blah does not always return false. I must 
say that $blah ne $blah1 is a better description I wish I still had some 
of the code that gave me these errors but i have come accross it a 
couple of times. Say i've got this,
$blah = "123";
$blah1 = "1234";

if ($blah ne $blah1) {
	print "They are not equal";
}

I know this works but sometimes when the values are different it doesn't 
always reconise they are not equal.

This message is probably useless without a real example. When I come 
accross it again i'll post it up. I was just wondering if anyone else 
had seen this problem.

Gary


Anno Siegel wrote:
> Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
> 
>>Hi,
>>Whilst i'm here i might as well see if anyone else has noticed strange 
>>things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
> 
> 
> Would you please explain what you mean by "doesn't work". "$blah ne
> $blah" will always return false.  It may also issue a warning if
> $blah is undefined.
> 
> 
>>I always end up doing it a different way as i start pulling my hair out 
>>because everything is correct it just doesn't work.
>>
>>Anyone else had that problem.
> 
> 
> What problem?
> 
> Anno



------------------------------

Date: 9 Dec 2003 13:15:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why does ne always work
Message-Id: <br4hu3$mbq$6@mamenchi.zrz.TU-Berlin.DE>

[reply put into sequence. please don't top-post]

Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gary Mayor  <gary@tgpmakers.com> wrote in comp.lang.perl.misc:
> > 
> >>Hi,
> >>Whilst i'm here i might as well see if anyone else has noticed strange 
> >>things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
> > 
> > 
> > Would you please explain what you mean by "doesn't work". "$blah ne
> > $blah" will always return false.  It may also issue a warning if
> > $blah is undefined.
> > 
> > 
> >>I always end up doing it a different way as i start pulling my hair out 
> >>because everything is correct it just doesn't work.
> >>
> >>Anyone else had that problem.

> That's what i mean $blah ne $blah does not always return false. I must 
> say that $blah ne $blah1 is a better description I wish I still had some 
> of the code that gave me these errors but i have come accross it a 
> couple of times. Say i've got this,
> $blah = "123";
> $blah1 = "1234";
> 
> if ($blah ne $blah1) {
> 	print "They are not equal";
> }
> 
> I know this works but sometimes when the values are different it doesn't 
> always reconise they are not equal.
> 
> This message is probably useless without a real example. When I come 
> accross it again i'll post it up. I was just wondering if anyone else 
> had seen this problem.

I think you are confusing "ne" with "!=".  If you compare two different
strings *numerically*, the result may be that they're equal because
they represent the same number, as in "003" and "3".  String comparison
(with "eq", "ne" and friends) always compares strings "as-is".

There *may* be weird effects with overloaded objects, but that is
in another category.  These effects have nothing to do with comparison,
but the strings you are comparing may not be the ones you think you
are comparing.

Anno


------------------------------

Date: Tue, 09 Dec 2003 13:17:32 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Why does ne always work
Message-Id: <MXjBb.4532$uz6.4383@nwrddc02.gnilink.net>

[Would you please stop top-posting?]
[Would you please stop blindly full-quoting?]

Gary Mayor wrote:
> That's what i mean $blah ne $blah does not always return false. I must
> say that $blah ne $blah1 is a better description I wish I still had

Well, there is quite a difference between comparing the same variable and
comparing two different variables, don't you think? Would have been nice not
to misslead everyone :-(

> some of the code that gave me these errors but i have come accross it
> a couple of times. Say i've got this,
> $blah = "123";
> $blah1 = "1234";
>
> if ($blah ne $blah1) {
> print "They are not equal";
> }
>
> I know this works

Please define "works".

> but sometimes when the values are different it
> doesn't always reconise they are not equal.

Ah, finally a statement with some meat on it.
So you are claiming that the operator 'ne' yields the wrong result in some
circumstances. Is that correct?

Well, you know, may I quote from
http://www.catb.org/~esr/faqs/smart-questions.html:
<quote>
      Q:.  My program doesn't work. I think system facility X is broken.

      A:.  While it is possible that you are the first person to notice an
obvious deficiency in system calls and libraries heavily used by hundreds or
thousands of people, it is rather more likely that you are utterly clueless.
Extraordinary claims require extraordinary evidence; when you make a claim
like this one, you must back it up with clear and exhaustive documentation
of the failure case.

</quote>

> This message is probably useless without a real example.

I would agree!

> When I come
> accross it again i'll post it up. I was just wondering if anyone else
> had seen this problem.

A wild guess:
In your example $blah and $blah1 are numbers, but you elected to denote and
compare them as strings.
If that is the style in which you usually write your programs, then I wonder
if maybe you ran into a 'perldoc -q 999' problem.

jue




------------------------------

Date: Tue, 09 Dec 2003 12:32:35 +0000
From: Gary Mayor <gary@tgpmakers.com>
Subject: Re: Why does ne not always work i meant
Message-Id: <br4f90$q6s$2@news6.svr.pol.co.uk>

Gary Mayor wrote:
> Hi,
> Whilst i'm here i might as well see if anyone else has noticed strange 
> things with if ($blah ne $blah) sometimes it works sometimes it doesn't. 
> I always end up doing it a different way as i start pulling my hair out 
> because everything is correct it just doesn't work.
> 
> Anyone else had that problem.
> 
> Gary
> 



------------------------------

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 5915
***************************************


home help back first fref pref prev next nref lref last post