[28521] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9885 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 24 14:06:16 2006

Date: Tue, 24 Oct 2006 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 24 Oct 2006     Volume: 10 Number: 9885

Today's topics:
        ActiveState Perl crashs, why ? <someone@somewhere.none>
    Re: c like structure in Perl <hjp-usenet2@hjp.at>
    Re: Can't find string terminator ... <softouch@softouch.on.ca>
    Re: Can't find string terminator ... <john@castleamber.com>
    Re: Can't find string terminator ... xhoster@gmail.com
    Re: File and directory permissions <rvtol+news@isolution.nl>
    Re: FTP to a windows file share? <bwilkins@gmail.com>
    Re: How can i find source code like Data::Dumper in per anno4000@radom.zrz.tu-berlin.de
    Re: How can i find source code like Data::Dumper in per <tadmc@augustmail.com>
    Re: How can i find source code like Data::Dumper in per <bik.mido@tiscalinet.it>
    Re: I have no problems eating cereal...after it softens <bwilkins@gmail.com>
        Perl SOAP::Lite NTLM authentication <michelin_nospam@tin.it>
    Re: Perl SOAP::Lite NTLM authentication <john@castleamber.com>
        Strange Perl line : Return the result of a function to  <awatier@gmail.com>
    Re: Strange Perl line : Return the result of a function <josef.moellers@fujitsu-siemens.com>
    Re: Strange Perl line : Return the result of a function <tadmc@augustmail.com>
    Re: Strange Perl line : Return the result of a function <hjp-usenet2@hjp.at>
    Re: Strange Perl line : Return the result of a function <quetzalcotl@consultant.com>
    Re: Strange Perl line : Return the result of a function <bik.mido@tiscalinet.it>
    Re: string substitution for a file, without replacing p <cwilbur@mithril.chromatico.net>
    Re: Why I no longer use Perl <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 24 Oct 2006 17:04:58 +0200
From: "perl" <someone@somewhere.none>
Subject: ActiveState Perl crashs, why ?
Message-Id: <ehla17$nto$1@online.de>

Hello,

when i run my little perl script, Perl crashes (using Win2000+ActiveState
Perl 5.8.8).
I have no idea why.

Here the little script:
---------------------------------
#!/usr/bin/perl -w

use LWP::UserAgent;
use strict;

my $url = "http://www.google.de";
my $ua = LWP::UserAgent->new(); # create virtual browser
$ua->agent("someagent/v 0.1a"); # giving browser a name

my $req = HTTP::Request->new(GET => $url);
my $webpage = $ua->request($req);

if ($webpage->is_success){ print $webpage->content;}
else {print $webpage->status_line, "\n";}
-----------------------------------

It works under Linux, so there should be no reason to crash. I discovered
that the crash happens, when GET is called.




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

Date: Tue, 24 Oct 2006 17:03:00 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: c like structure in Perl
Message-Id: <slrnejsap4.20q.hjp-usenet2@yoyo.hjp.at>

[I'm following up to Dr.Ruud because I want to expand his good advice,
but it is really an answer to the OP - so "you" in the following refers
to adarsh.hrbr@gmail.com]

On 2006-10-24 09:48, Dr.Ruud <rvtol+news@isolution.nl> wrote:
> adarsh.hrbr@gmail.com schreef:
>> Below is a structure in c which I want to type cast. Can somebody
>> suggest a method to define this in Perl so that I can typecaste the
>> same in my Server to obtain the data.
>>
>> typedef struct {
>>
>>       uint8 Reserved;
>>       uint32 ipaddr;
>>       uint32 netmask;
>>       uint16 command;
>>
>> } sample;
>>
>> uint - unsigned int type - 8,16 and 32 bytes - in length

ITYM bits, not bytes.


> The sizeof(sample) doesn't need to be 11.

Indeed it is unlikely to be 11. Almost every C compiler will insert
three padding bytes between "Reserved" and "ipaddr" to get the latter on
a 32 bit boundary (and another 2 bytes at the end for the same reason).
But some compilers may pad only to 16 bits or not at all. 

Avoid the use of structs in I/O. It looks simple at first, but isn't -
you need to carefully lay out your structs to avoid padding issues and
then you still have to deal with endianness and other representation
issues - better to define your protocol as a byte stream in the first
place.

Since you are probably stuck with the server, use Dr. Ruud's
advice:

> If not, use 'offsetof(s,m)', or subtract pointers, to find out where
> the members are in the struct.  See also #pragma pack().

to document the current behaviour and make it mandatory: I.e. if you
find that the struct really looks like this (which I would guess for
modern C-compilers):

   typedef struct {
  
         uint8 Reserved;
         uint8 Reserved1;
         uint8 Reserved2;
         uint8 Reserved3;
         uint32 ipaddr;
         uint32 netmask;
         uint16 command;
         uint8 Reserved4;
         uint8 Reserved5;
  
   } sample;

define that this is the intended format: 4 reserved bytes, followed by 4
bytes ipaddr, 4 bytes netmask, 2 bytes of command and another 2
reserved bytes. Also you probably must standardize on some byte order
(preferrably network byte order (big endian) since you already have an
ip-address and a netmask in there).

Then - and only then, not before - use pack/unpack to create/parse the
format you have defined.

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Tue, 24 Oct 2006 10:41:11 -0400
From: Amer Neely <softouch@softouch.on.ca>
Subject: Re: Can't find string terminator ...
Message-Id: <%Bp%g.122110$ED.69605@read2.cgocable.net>

Michele Dondi wrote:
> On Mon, 23 Oct 2006 16:42:52 -0400, Amer Neely
> <softouch@softouch.on.ca> wrote:
> 
>>> You're sure there is a newline after EndOfText?
>>>
>>> Might be that you have accidently pressed a key combination that inserts a 
>>> hidden character in your terminator. I would delete EndOfText (twice), and 
>>> type it in again (once), and copy it.
>>>
>> Believe me, I've tried everything I can think of to ensure there is 
>> nothing else on that line except the newline at the end. There is 
>> something very strange going on here.
> 
> Not to distrust you, but what about cat -A?
> 
> 
> Michele

Hmm. That looks like a *nix command, but I'm running on Windoze 2K. I 
did solve the immediate problem as posted, but it still doesn't answer 
why this situation arose in the first place. I guess I'll never know.

-- 
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
v: 705.223.3539
Perl | MySQL programming for all data entry forms.
"We make web sites work!"


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

Date: 24 Oct 2006 17:04:53 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Can't find string terminator ...
Message-Id: <Xns98667AE544599castleamber@130.133.1.4>

Amer Neely <softouch@softouch.on.ca> wrote:

> Hmm. That looks like a *nix command, but I'm running on Windoze 2K. I 
> did solve the immediate problem as posted, but it still doesn't answer
> why this situation arose in the first place. I guess I'll never know.

I recall that you wrote that there was an additional \x0a in your code.

Furthermore, you can install cat, ls, grep, wget, etc. [1] on a computer 
running Windows 2000 (If you don't like Windows, and need to call it 
Windoze, why are you using it in the first place?)

[1] http://johnbokma.com/mexit/2006/07/01/

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 24 Oct 2006 17:12:13 GMT
From: xhoster@gmail.com
Subject: Re: Can't find string terminator ...
Message-Id: <20061024131238.598$v7@newsreader.com>

Amer Neely <softouch@softouch.on.ca> wrote:
> xhoster@gmail.com wrote:
> >
> > perl -0777 -ne "print ord, qq{\t$_\n} foreach split //" eot.pl
> >
> > (and change. eot.pl to whatever file name you acutally used)
> >
> > Xho
> >
> Thanks.
> Got it:
> D:\httpd\cgi-bin\hasbeans\dev>perl -0777 -ne "print ord,qq{\t$_\n}
> foreach split //" test.pl


 ...
> 119     w
> 116     t
> 102     f
> 13
> 10
>
> 69      E
> 110     n
> 100     d
> 84      T
> 101     e
> 120     x
> 116     t
> 13
> 10
>
> D:\httpd\cgi-bin\hasbeans\dev>
>
> I see the CR-LF pair, but should there also be that blank line between
> blocks?

Yes, becuase I print both the ord and the $_ itself.  Printing the $_
when $_ contains chr(10) is what is causing the blank lines.  You could
make is supress the printing of $_ (but still print ord($_)) when $_ is not
an ordinary character, but I'm too lazy.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 24 Oct 2006 12:24:11 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: File and directory permissions
Message-Id: <ehl0m9.tc.1@news.isolution.nl>

ismael schreef:

> I have some problems to get the the permissions on windows with Perl
> code. I use a simple code that run perfectly in UNIX but give me
> wrong information on Windows. This is the code:
>
> $file = "/home/ismael/pruebaperl/fichero.txt";
> print "Starting to analize $file\n";
> if (-e $file){
>     print "found\n";
>     }
> else {
>     print "not found\n";
>     }
> if (-x $file){
>     print "executable\n";
>     }
> if (-r $file){
>     print "readable\n";
>     }
> if (-w $file){
>     print "writable\n";
>     }
> print "finished\n";
>
> This code allways say that file is readable and writable except if is
> a read only file.
> is there a solution for this?, one library or code? Anything that i do
> wrong?

This effect has been reported some times before. I assume that you need
to use a Win32-specific module to get "better" information on files in
Windows, because the permissions-system of Windows is very different.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: 24 Oct 2006 06:20:13 -0700
From: "Brian  Wilkins" <bwilkins@gmail.com>
Subject: Re: FTP to a windows file share?
Message-Id: <1161696013.912423.289180@e3g2000cwe.googlegroups.com>


l v wrote:
> MattJ83 wrote:
> >> I just started to read this thread so I'm sorry if this was discussed
> >> and I just missed it.  I'm guessing that windows server ukbr1234 has a
> >> shared directory called 'shared' with a sub-directory called test.  This
> >> share is physically located on the server, for example, at d:\share\test
> >> on ukbr1234.  Correct?
> >
> > \\ukbr1234\share\test is the location yes......so when it is mapped to
> > a drive it becomes Y:\test
> >> You need to copy some unix files to \\ukbr1234\share\text.  Correct?
> >>
> >
> > yes. Im logged onto the unix server through hummingbird and want the
> > files to copy to a windows server.
> >
> >> Is ftp installed on the windows server?
> > not sure
> >
> >> If not, can ftp be installed on this server?
> > not sure
> >
> > ^^^^^^^^^ the server is a storage server and doesn't allow anyone to
> > login remotely. You have to be at the machine (which I don't have
> > access to) so apart from not being able to easily find out - I think
> > the installing of items would be hard!
>
> It's easy to find out, from the unix server or your pc (not exceed), try
> to ftp to the windows server from the command line.  If it prompts for
> login, then ftp is running.  Remote desktop is not needed to determine
> if ftp is installed and running, however, it is needed to determine if
> it is installed and not running.
>
> Sounds like you have a valid business case for the windows server owner
> to install ftp.
>
>
> >> If ftp is or can be installed, then you can create an virtual ftp
> >> directory pointing to d:\share\test.  The unix server can then ftp to
> >> the windows server just like you ftp to a unix server using Net::FTP.
> >> The windows share \\ukbr1234\share\test will contain the unix files when
> >> accessing from your desktop.  Is this what you are looking for?
> >>
> >
> > this is spot on what i am looking for.......
> > i was orignally looking at mapping to a windows share in perl and then
> > transfering files across that way thats why i was looking at
> > Win32::NetResource:
> > http://www.codecomments.com/archive210-2004-3-154919.html
>
> I'm not aware of being able to map a windows share within native unix.
> I believe that is a windows to windows thing.  But I could be wrong.
> You need something to mount a windows share into your unix file system.
>   Someone mentioned Samba can do this.  I do not know how Samba works,
> but if you need to install it on your windows server, ftp would be
> easier choice IMO.
>
>
> --
>
> Len

Samba is installed on the Unix/Linux machine. He sets up a normal
Windows share and Samba allows you to mount the Windows share on to
your Nix filesystem. He will have to alter his syntax for accessing the
file share as the UNC filenames we described above won't work on a Nix
machine because they do not recognize it. It seems he does not have
ready access to the machine so installing new software on the machine
may not be a good choice. I would use Windows share or the FTP service
rather than installing a full-fledged server that needs maintenance
(since he can't access it remotely anyways). 
YMMV



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

Date: 24 Oct 2006 11:56:32 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How can i find source code like Data::Dumper in perl package
Message-Id: <4q6dbgFln6riU1@news.dfncis.de>

 <jagon.cn@gmail.com> wrote in comp.lang.perl.misc:
> i am running on linux box and i am trying to find the module source
> code of Data::Dumper from my perl lib /usr/lib/perl5, but i can not get
> it.
> 
> Is there anyone who can tell me how to find it on my machine or
> actually it does not exist. I also can not find Net::SSLeay.

This is what I use:

    #!/usr/local/bin/perl
    use strict; use warnings; $| = 1;

    for ( shift ) {
        s/(?<!\.pm)$/.pm/;
        s{::}{/}g;
        require;
        $INC{ $_} or die "Can't find module '$_' in \%INC";
        exec '/usr/bin/view', $INC{ $_};
    }

Anno


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

Date: Tue, 24 Oct 2006 07:28:26 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How can i find source code like Data::Dumper in perl package
Message-Id: <slrnejs1na.p5a.tadmc@tadmc30.august.net>

anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> <jagon.cn@gmail.com> wrote in comp.lang.perl.misc:
>> i am running on linux box and i am trying to find the module source
>> code of Data::Dumper from my perl lib /usr/lib/perl5, but i can not get
>> it.
>> 
>> Is there anyone who can tell me how to find it on my machine or
>> actually it does not exist. I also can not find Net::SSLeay.
>
> This is what I use:
>
>     #!/usr/local/bin/perl
>     use strict; use warnings; $| = 1;
>
>     for ( shift ) {
>         s/(?<!\.pm)$/.pm/;
>         s{::}{/}g;
>         require;
>         $INC{ $_} or die "Can't find module '$_' in \%INC";
>         exec '/usr/bin/view', $INC{ $_};
>     }


This is what I use:

   perldoc -l Data::Dumper

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 24 Oct 2006 16:20:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How can i find source code like Data::Dumper in perl package
Message-Id: <e68sj294keraj4mgmqvqmehl6tlflekpfo@4ax.com>

On Tue, 24 Oct 2006 07:28:26 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:

>> This is what I use:
>>
>>     #!/usr/local/bin/perl
>>     use strict; use warnings; $| = 1;
>>
>>     for ( shift ) {
>>         s/(?<!\.pm)$/.pm/;
>>         s{::}{/}g;
>>         require;
>>         $INC{ $_} or die "Can't find module '$_' in \%INC";
>>         exec '/usr/bin/view', $INC{ $_};
>>     }
>
>
>This is what I use:
>
>   perldoc -l Data::Dumper

Again, <news:1kvhj2d7j9ihoc6iejmep76tf3o5vbcq6r@4ax.com> for a pointer
to... basically the same discussion! ;-)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 24 Oct 2006 05:26:19 -0700
From: "Brian  Wilkins" <bwilkins@gmail.com>
Subject: Re: I have no problems eating cereal...after it softens. Why is replacing a simple string so hard then?
Message-Id: <1161692779.078242.107880@k70g2000cwa.googlegroups.com>


Dave Weaver wrote:
> On 17 Oct 2006 16:48:18 -0700, Brian  Wilkins <bwilkins@gmail.com> wrote:
> >
> >
> >  samiam@mytrashmail.com wrote:
> >  [snipped]
> >
> >  Why don't you read in the web page into a scalar variable and chomp all
> >  the \n characters. Then you have a large scalar variable all on one
> >  line. Like so (caution not tested):
> >
> > ====
> >
> >  use strict;
> >  use warnings;
> >  use HTML::TokeParser;
> >
> >  $data_file="webpage.htm";
>
> That doesn't compile. You "use strict" but then you don't
> declare your variables
>
>     my $data_file = "webpage.htm"
>
> >  open(DAT, $data_file) || die("Could not open file!");
>
> The error message would be more informative if it included $!
> Also, it is generally better to use lexical file handles and the
> 3-argument form of open:
>
>     open my $dat, '<', $data_file
> 	    or die "Couldn't open '$data_file' because: $!"
>
> >
> >  @raw_data=<DAT>;
>
>     my @raw_data = <$dat>;
>
> >
> >  close(DAT);
> >
> >  foreach $line (@raw_data)
>
> missing "my". And I find "for" easier on the eye than "foreach". YMMV
>
>     for my $line (@raw_data)
>
> >  {
> >    chomp($line);
> >    $rawHTML .= $line;
> >  }
>
> Why are you removing all the line-end characters from the data?
> That will break HTML files that have <PRE></PRE> sections, at least.
>
> All the code above would be better written as:
>
>     open my $dat, '<', $data_file
> 	    or die "Couldn't open '$data_file' because: $!"
>     my $rawHTML = do { local $/; <$dat> };
>     close $dat;
>
> Or, better still:
>
>     use File::Slurp;
>     my $rawHTML = read_file( $data_file );
>
> >
> >  $rawHTML =~ s#<form .*?</form>#BLOCK#sg;
>
> As others have mentioned, a regex is a poor way to parse HTML.
>
> >  open(OUTFILE, ">parsed_file.htm");
>
>     open my $outfile, '>', "parsed_file.htm"
> 	or die "Can't write to parsed_file.htm because: $!";
> >
> >  print OUTFILE $rawHTML;
> >
> >  close(OUTFILE);
>
> If you used File::Slurp, then replace the above with:
>
>     write_file( 'parsed_file.htm' );
>
>
> >  You can also use HTML::TokeParser. It may work better in this case.
>
> It work work better than a plain s/// for most HTML.

All your comments are OBE as I explained that HTML::TokeParser works
better and the code was written off the cuff.



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

Date: Tue, 24 Oct 2006 17:35:50 GMT
From: "michelin" <michelin_nospam@tin.it>
Subject: Perl SOAP::Lite NTLM authentication
Message-Id: <W9s%g.15529$uv5.118706@twister1.libero.it>

Hi to all,

I'm writing a perl script that has to invoke a Microsoft .net WebService.
The WebService is hosted on a Windows Server 2003 host with NTLM 
Authentication.

I'm using SOAP::Lite as soap toolkit, of course.

According to SOAP::Lite official documentation (and other examples on the 
Internet), basic and digest authentication are fully supported, but I can't 
find any reference to NTLM authentication ... somebody knows if it is 
possibile to use NTLM authentication with SOAP::Lite?
Could you give me some reference, materials and code examples?

Thanks in advance

Domenico




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

Date: 24 Oct 2006 17:56:45 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Perl SOAP::Lite NTLM authentication
Message-Id: <Xns986683B03EDBFcastleamber@130.133.1.4>

"michelin" <michelin_nospam@tin.it> wrote:

> Hi to all,
> 
> I'm writing a perl script that has to invoke a Microsoft .net
> WebService. The WebService is hosted on a Windows Server 2003 host
> with NTLM Authentication.
> 
> I'm using SOAP::Lite as soap toolkit, of course.
> 
> According to SOAP::Lite official documentation (and other examples on
> the Internet), basic and digest authentication are fully supported,
> but I can't find any reference to NTLM authentication ... somebody
> knows if it is possibile to use NTLM authentication with SOAP::Lite?
> Could you give me some reference, materials and code examples?

Wild guess:
http://search.cpan.org/search?query=LWP%3A%3AAuthen%3A%3ANtlm+&mode=all

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 24 Oct 2006 06:19:20 -0700
From: "AlexHWGUY" <awatier@gmail.com>
Subject: Strange Perl line : Return the result of a function to a function
Message-Id: <1161695960.426695.284850@e3g2000cwe.googlegroups.com>

I never done a Perl code before but I done some C, PHP, JAVA, etc...
Peel looked very similar before I failed to understand those lines :

substr($y, 5, 2) = substr($y, 4, 2);
substr($y, 4, 1) = ".";

How that possible ? It is replacing the 2 char at pos 5 with 2 char at
pos 4 ?

Thanks to help me put my eyes back in their hole.



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

Date: Tue, 24 Oct 2006 15:39:24 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Strange Perl line : Return the result of a function to a function
Message-Id: <ehl59m$dgg$1@nntp.fujitsu-siemens.com>

AlexHWGUY wrote:
> I never done a Perl code before but I done some C, PHP, JAVA, etc...
> Peel looked very similar before I failed to understand those lines :
>=20
> substr($y, 5, 2) =3D substr($y, 4, 2);
> substr($y, 4, 1) =3D ".";
>=20
> How that possible ? It is replacing the 2 char at pos 5 with 2 char at
> pos 4 ?
>=20
> Thanks to help me put my eyes back in their hole.
>=20

It does indeed look strange, but (from "perldoc -f substr"):

"You can use the substr() function as an lvalue, in which case EXPR must =

itself be an lvalue."

So it works as designed.

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Tue, 24 Oct 2006 09:10:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Strange Perl line : Return the result of a function to a function
Message-Id: <slrnejs7nc.ptv.tadmc@tadmc30.august.net>

Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> AlexHWGUY wrote:
>> I never done a Perl code before but I done some C, PHP, JAVA, etc...
>> Peel looked very similar before I failed to understand those lines :
>> 
>> substr($y, 5, 2) = substr($y, 4, 2);
>> substr($y, 4, 1) = ".";
>> 
>> How that possible ? It is replacing the 2 char at pos 5 with 2 char at
>> pos 4 ?
>> 
>> Thanks to help me put my eyes back in their hole.
>> 
>
> It does indeed look strange, but (from "perldoc -f substr"):
>
> "You can use the substr() function as an lvalue, in which case EXPR must 
> itself be an lvalue."
>
> So it works as designed.


And if you use the 4-argument form of substr(), then your eyeballs will
stay in their sockets.   :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 24 Oct 2006 17:12:03 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Strange Perl line : Return the result of a function to a function
Message-Id: <slrnejsba3.20q.hjp-usenet2@yoyo.hjp.at>

On 2006-10-24 13:19, AlexHWGUY <awatier@gmail.com> wrote:
> I never done a Perl code before but I done some C, PHP, JAVA, etc...
> Peel looked very similar before I failed to understand those lines :
>
> substr($y, 5, 2) = substr($y, 4, 2);
> substr($y, 4, 1) = ".";
>
> How that possible ? It is replacing the 2 char at pos 5 with 2 char at
> pos 4 ?

Yes.

That form is now by many considered deprecated, but I wonder whether the
alternative 

substr($y, 5, 2, substr($y, 4, 2));
substr($y, 4, 1, ".");

is really more readable. At least the assignment makes it clear what is
replaced (you obviously found the right answer without checking the
manual), while for the 4-argument form you have to look up the manual to
find out that there is a replacement at all.

	hp

PS: For replacing parts of a string I prefer the s/// operator, even if
it is somewhat slower.

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 24 Oct 2006 08:31:17 -0700
From: "Ingo Menger" <quetzalcotl@consultant.com>
Subject: Re: Strange Perl line : Return the result of a function to a function
Message-Id: <1161703877.151591.316650@m73g2000cwd.googlegroups.com>


Peter J. Holzer wrote:
> On 2006-10-24 13:19, AlexHWGUY <awatier@gmail.com> wrote:
> > I never done a Perl code before but I done some C, PHP, JAVA, etc...
> > Peel looked very similar before I failed to understand those lines :
> >
> > substr($y, 5, 2) = substr($y, 4, 2);
> > substr($y, 4, 1) = ".";
> >
> > How that possible ? It is replacing the 2 char at pos 5 with 2 char at
> > pos 4 ?
>
> Yes.
>
> That form is now by many considered deprecated, but I wonder whether the
> alternative
>
> substr($y, 5, 2, substr($y, 4, 2));
> substr($y, 4, 1, ".");
>
> is really more readable.

Full ACK. After all, people are used to read and write things like

 $a[2] = 42;

without ever noticing that the construct on the left hand side means
something totally different when it is used on the right hand side.



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

Date: 24 Oct 2006 17:45:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Strange Perl line : Return the result of a function to a function
Message-Id: <4tcsj25sn2u79mphff497d7abb9kt3ccku@4ax.com>

On Tue, 24 Oct 2006 17:12:03 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:

>> substr($y, 5, 2) = substr($y, 4, 2);
>> substr($y, 4, 1) = ".";
[snip]
>That form is now by many considered deprecated, but I wonder whether the
>alternative 

Not only did I not know that many consider it deprecated, but also:

http://perlmonks.org/?node_id=498434

Please note that the special behaviour of substr() in this sense is
not there to make for witty syntax or funny tricks, but to serve an
actual purpose, e.g. in connection with efficient ways to do "in-place
editing on huge, fixed record length files".


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 24 Oct 2006 08:40:02 -0400
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <871woxkhul.fsf@mithril.chromatico.net>

"Arved Sandstrom" <asandstrom@accesswave.ca> writes:

> <anno4000@radom.zrz.tu-berlin.de> wrote in message 
> news:4q2400Fl66k4U1@news.dfncis.de...
> > gavino <bootiack@yahoo.com> wrote in comp.lang.perl.misc:
> >
> >> Didn't work
> >
> > That's a pretty rude reply to a helpful message, don't you think?
> > Not to mention the lack of any context.
> 
> Come, come, that's the standard initial reply from a disgruntled consumer. 
> Have you never worked tech support for a software product? :-)

More to the point, it's completely @#$%ing useless.

Matters of politeness aside, one has to assume that the OP wants his
problem solved, but his apparent lack of comprehension of what it
takes to solve problems (i.e., specific feedback about what didn't
work and in what way it didn't work) suggests that he's going to be
solving this one on his own.

It's one thing when you're being paid to tease out information from
people who don't know any better.  It's quite another entirely when
you're volunteering your time to be helpful.

Charlton




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

Date: Tue, 24 Oct 2006 16:34:28 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Why I no longer use Perl
Message-Id: <slrnejs93k.20q.hjp-usenet2@yoyo.hjp.at>

On 2006-10-24 09:14, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Mon, 23 Oct 2006 21:57:48 +0200, "Peter J. Holzer"
><hjp-usenet2@hjp.at> wrote:
>
>>You don't include enough information about your environment to be sure
>>where the bug is, but it is probably in perl 5.8.0 and was later
>>fixed.  There were quite a few unicode-related bugs in 5.8.0. However,
>>perl 5.8.0 is now more than 4 years old and was superceded by perl
>>5.8.1 more than three years ago.
>
> However AIUI the point is that for some reason the OP seems to find
> 5.8.0's buggy behaviour to be the "right" one...

Not quite. AIUI he found perl 5.8.8 behaviour in the first example
correct but the 5.8.0 behaviour in the second example. But that was
because he had an error in the second example.

Unfortunately the Perl behaviour with UTF-8 is not very intuitive. While
it is backward compatible and allows you to work with both byte-oriented
and character oriented data with relatively little trouble *after*
you've grokked the concepts, the learning-curve is rather steep. You
really need to understand the difference between byte strings and
character strings as well as the influence of I/O layers, environment
variables and conversion functions to make sense of the behaviour. 

I doubt that it is much simpler in Python, though. 

It might be simpler in a strongly typed language such as Java
(somebody's going to point out now that Java isn't really strongly
typed, either), where you have different types for character strings and
byte strings, but in reality it isn't: The difference isn't always
crystal-clear, and you will have some standard library which got it
wrong and which can't be fixed because that would break every program
which uses it.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

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 V10 Issue 9885
***************************************


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