[22619] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4840 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 13 18:05:59 2003

Date: Sun, 13 Apr 2003 15:05:10 -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           Sun, 13 Apr 2003     Volume: 10 Number: 4840

Today's topics:
    Re: 64bit Perl <No_4@dsl.pipex.com>
    Re: Convert curses screen output to space-delimited tex <dickey@saltmine.radix.net>
        Determine type of file ascii or bin <Ras@majere.demon.co.uk>
    Re: Determine type of file ascii or bin <joe@benburb.demon.co.uk>
    Re: Determine type of file ascii or bin <uri@stemsystems.com>
    Re: Determine type of file ascii or bin <noreply@gunnar.cc>
    Re: Dynamic loading of modules <arevos@arevol.co.uk>
    Re: executing perl script (David Efflandt)
    Re: help with using Net-Telnet module.. (supportgeek)
    Re: maps and regexs <eric-amick@comcast.net>
    Re: My 1st japh!! <bik.mido@tiscalinet.it>
    Re: My 1st japh!! <tassilo.parseval@rwth-aachen.de>
    Re: need help in parseing file with a wierd arrangment  <spam@thecouch.homeip.net>
        Network socket - binary data. <Ras@majere.demon.co.uk>
        Preventing users from ending script + checking admin ri (Gert Vanderstukken)
        Return value from perl module <shasha1980@hotmail.com>
    Re: Return value from perl module <shasha1980@hotmail.com>
        search with unicode charaters (FMAS)
    Re: Shortcut <jurgenex@hotmail.com>
    Re: Shortcut <wsegrave@mindspring.com>
    Re: Shortcut <mail@annuna.com>
    Re: Shortcut <mbudash@sonic.net>
    Re: Shortcut <cybergrafx@hotmail.com>
    Re: Shortcut <uri@stemsystems.com>
    Re: Shortcut <abigail@abigail.nl>
    Re: split question (Bruno Skorepa)
        What is wrong? <mail@annuna.com>
    Re: What is wrong? <mail@annuna.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 13 Apr 2003 12:59:05 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: 64bit Perl
Message-Id: <3e995107$0$11379$cc9e4d1f@news.dial.pipex.com>

Tom Hoffmann wrote:
> I had a similar problem on AIX w/ 64 bit Oracle trying to make DBD::Oracle.
> I ended up modifying the Makefile to use the Oracle 32-bit libraries. That
> is, I changed all references to the 64-bit Oracel lib (../lib) to the 32-bit
> Oracle lib (../lib32). IIRC, I also had to change all refernces to ctr-64.o
> to crt.o.

    On SGI Irix the Oracle config looks for any environment setting of 
SGI_ABI and if it is -n32 (which would make the compiler produce 32bit 
code) it behaves accordingly.  Perhaps other architectures have a 
similar mechanism?

-- 
      -*-    Just because I've written it here doesn't    -*-
      -*-    mean that you should, or I do, believe it.   -*-



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

Date: 13 Apr 2003 12:02:18 GMT
From: Thomas Dickey <dickey@saltmine.radix.net>
Subject: Re: Convert curses screen output to space-delimited text output ?
Message-Id: <b7bjka$ap4$4@news1.radix.net>

Sean O'Neill <sean@deletethistorespond.seanoneill.deletethistorespond.info> wrote:

> It almost seems to make this work I would have to do the following:

that sounds like what I was talking about, yes.

> BTW, where can I get information about what the various elements in
> termcap mean, e.g. do, le, ce, md, etc ?

The terminfo manpage (e.g., "man 5 terminfo" on Linux, "man -s 4 terminfo"
on Solaris) has a rather terse table and some discussion as well.  The
table has a mapping of terminfo names to termcap.  (FreeBSD's copy of
this is not formatted properly, btw - a sed script tweak that was reported
after ncurses 5.3).  There's an html version of it via my ncurses faq,
near the bottom -

The current version of ncurses is 5.3 (20021012)
There's an faq at
	http://invisible-island.net/ncurses/ncurses.faq.html

-- 
Thomas E. Dickey <dickey@radix.net> <dickey@herndon4.his.com>
http://dickey.his.com
ftp://dickey.his.com


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

Date: Sun, 13 Apr 2003 19:43:44 +0100
From: "Ras" <Ras@majere.demon.co.uk>
Subject: Determine type of file ascii or bin
Message-Id: <b7carp$87j$1$8302bc10@news.demon.co.uk>

Need a pointer...

What's the easiest way to determine if a file is binary or ASCII  ? this
would change the way you read and write. {i think}

i need to move a file and i wont always know what type of file. i have
noticed sending asci files as bin via ftp can cause wonderful results

thanks for any help

Ford




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

Date: 13 Apr 2003 20:05:07 +0100
From: Joe Mc Cool <joe@benburb.demon.co.uk>
Subject: Re: Determine type of file ascii or bin
Message-Id: <86wuhy43rw.fsf@benburb.demon.co.uk>

"Ras" <Ras@majere.demon.co.uk> writes:

> What's the easiest way to determine if a file is binary or ASCII  ? this
> would change the way you read and write. {i think}
> 
> i need to move a file and i wont always know what type of file. i have
> noticed sending asci files as bin via ftp can cause wonderful results

For ftp just assume binary all the time !

Joe


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

Date: Sun, 13 Apr 2003 19:50:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Determine type of file ascii or bin
Message-Id: <x73ckmfa7o.fsf@mail.sysarch.com>

>>>>> "JMC" == Joe Mc Cool <joe@benburb.demon.co.uk> writes:

  JMC> "Ras" <Ras@majere.demon.co.uk> writes:
  >> What's the easiest way to determine if a file is binary or ASCII  ? this
  >> would change the way you read and write. {i think}
  >> 
  >> i need to move a file and i wont always know what type of file. i have
  >> noticed sending asci files as bin via ftp can cause wonderful results

  JMC> For ftp just assume binary all the time !

brilliant! and then you will have to deal with line ending conversions
later. and we all know how much fun that can be. and what nice effects
it has on line oriented code.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 13 Apr 2003 22:18:31 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Determine type of file ascii or bin
Message-Id: <b7cgn0$crv8v$1@ID-184292.news.dfncis.de>

Ras wrote:
> Need a pointer...
> 
> What's the easiest way to determine if a file is binary or ASCII  ?

     print 'This is a ' . (-T $file ? 'ASCII' : 'binary') . ' file';

     http://www.perldoc.com/perl5.8.0/pod/func/-X.html

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sun, 13 Apr 2003 13:42:04 +0100
From: James Reeves <arevos@arevol.co.uk>
Subject: Re: Dynamic loading of modules
Message-Id: <A7ema.2335$Aq1.439@newsfep4-winn.server.ntli.net>

Benjamin Goldberg wrote:

>    my $package = ucfirst $pagename;
>    require "$pack.pm";
>    no strict 'refs';
>    my $page = &{ $package . "::output" }( \%args, \%session );

Thanks! Worked like a charm :)

-- 
James Reeves
http://www.arevol.co.uk


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

Date: Sun, 13 Apr 2003 21:45:06 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: executing perl script
Message-Id: <slrnb9jmj1.fjn.efflandt@typhoon.xnet.com>

On 12 Apr 2003 02:09:46 -0700, bhat <rnbhat89@yahoo.com> wrote:
> Hello,
>  I am able to execute the below script from the command prompt.
> However when i try to run through internet explorer the script doesn't
> work as intended. The variable $folder in the script below now has
> null value. Seems like it doesn't execute any command after the
> statement my $msg = $folder->message(0);. I don't see any error
> messages. Any clues to solve this problem would be appriciated.
> Regards,
> Roopa

You did not specify web server and OS, but I assume that you have
successfully run other CGI on that server (?).

It could be that the user CGI is running as, does not have permission to
open sockets.  To test that theory try the following as CGI (lifted and
modified from 'perldoc perlipc'):

#!/usr/bin/perl -w
use strict;
use Socket;
use CGI::Carp qw(fatalsToBrowser);
my ($remote,$port, $iaddr, $paddr, $proto, $line);
$remote  = 'mail.xxxx.net';	### your pop3 server
$port    = 'pop3';
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port" unless $port;
$iaddr   = inet_aton($remote) || die "no host: $remote";
$paddr   = sockaddr_in($port, $iaddr);
$proto   = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SOCK, $paddr) || die "connect: $!";
print "Content-type: text/plain\n\n";
if (defined($line = <SOCK>)) {
    print $line;
} else {
    print "nothing read from $remote socket\n";
}
close (SOCK) || die "close: $!";
exit;


If that works in the shell and fails as CGI, then any Perl modules that 
use sockets will likely fail as CGI.

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 13 Apr 2003 07:28:23 -0700
From: molivier@caregroup.harvard.edu (supportgeek)
Subject: Re: help with using Net-Telnet module..
Message-Id: <da063e5d.0304130628.3b744a81@posting.google.com>

since you were using vbscript, it can be safely assumed that your
working on a windows based network. Look into the Win32 modules.
www.rothconsulting.com


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

Date: Sun, 06 Apr 2003 17:28:45 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: maps and regexs
Message-Id: <10719vkp23v28ot309jha3958v2tqvq5aa@4ax.com>

On Sun, 6 Apr 2003 15:32:38 -0500, tadmc@augustmail.com (Tad McClellan)
wrote:

>Tony McNulty <acm2@ukc.ac.uk> wrote:
>
>> I have a string as such: "thisismystring" and want to analyse the letters 
>> in sets of threes. I'm also learning more about maps and regexs too at the 
>> moment, and wanted to do this using either of the two.
>
>
>> I'm just looking for a pointer really as 
>> to how I can go about this using either a map, or a regex.
>
>
>   foreach my $str3 ( map substr($string, $_, 3), 0..length($string)-3 ) {

length($string)-2, actually.

-- 
Eric Amick
Columbia, MD


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

Date: Sun, 13 Apr 2003 18:56:44 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My 1st japh!!
Message-Id: <ol4j9v80h9knrhk7jglamakc63ocme7cjg@4ax.com>

On Fri, 11 Apr 2003 16:10:58 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

>Also, skilled perl programmers can see past tricks like using alternate
>delimiters with q, qq, and qw -- those only obscure things a little bit.

So it might be worth to further obscure them by means of some 'eval'
trickery, as in the new one below, but... would that be considered
"ethical"? I'm sure I've seen japhs using eval, but OTOH it's a bite
like "hey, it's too easy that way", isn't it?

>Obscuring the source of the data itself, on the other hand, is much
>cooler, imho.

granted!

>I prefer my own japh from a while back.
>
>   tr/`/ /, s/.//, print "@{[map --$| ? ucfirst lc : lc, split]},\n"
>   for pack 'u',pack 'H*','ab5cf4021bafd28972030972b00a218eb9720000'

I do prefer it too... and it would be great if I could (fully)
understand it!!


Michele
-- 
$\=q.,.,$_=q.print'  ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;


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

Date: 13 Apr 2003 17:03:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: My 1st japh!!
Message-Id: <b7c59v$n8d$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Michele Dondi:

> On Fri, 11 Apr 2003 16:10:58 -0400, Benjamin Goldberg
><goldbb2@earthlink.net> wrote:
> 
>>Also, skilled perl programmers can see past tricks like using alternate
>>delimiters with q, qq, and qw -- those only obscure things a little bit.
> 
> So it might be worth to further obscure them by means of some 'eval'
> trickery, as in the new one below, but... would that be considered
> "ethical"? I'm sure I've seen japhs using eval, but OTOH it's a bite
> like "hey, it's too easy that way", isn't it?

No, eval is fine. It certainly allows for very contorted and obscure
control-flow and data-hiding. I think the only thing that should be used
seldom in JAPHs is chr(). It blurs things only on the very first sight.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sun, 13 Apr 2003 15:14:46 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: need help in parseing file with a wierd arrangment of data
Message-Id: <HGima.3256$EK2.89576@wagner.videotron.net>

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

Triger wrote:
> I have a file that we need to read evey hour it happens to have a wierd format 
> any help in parseing it would be appreciated
> 
> Background
> We have a Load system that measures loads on electrical components each hour  
> and records those values.  each value has a unique tag (key) associated with 
> it and is stored as the tag + the value for the hour
> 
> a tag looks like the following :  11FISK3P   We have send the load system a 
> file with 50,000 tags like it and every hour it reads that file looks at the 
> tags we requested extracts the data for the tag and sends it to us
> 
> The file being sent is an ASCII comma separated value file. Data is coming in 
> the form of:  
> 
> Two lines 
> 1st - Date format used, tag, tag, tag, tag, tag,tag,...50,000th tag
> 2nd- date value, tag value,tag value,tag value,tag value,..50,000th tag value
> 
> sample: (showing 3 tags and values)
> 
> %d-%b-%y %H:%M:%S,11FISK3P,714MEDP,56TYRFT,...
> 3/4/2003 10:15,104, 8567, 5674.2, ..,
> 
> we need to create a file with the following format.  note that the instead of 
> 2 lines each tag tagvalue combination is in its own line giving me 50,000 
> lines
> 
> is this possible with perl
> 
> DateTime              Tag              hourly value
> 3/4/2003 10:15      11FISK3P    104
> 3/4/2003 10:15      714MEDP     8567
> 3/4/2003 10:15      56TYRFT      5674.2
> .
> .
> .
> 50,000th row    
> 

Here's a fairly clear (albeit slightly long) way of doing it.  It 
accepts the data via STDIN and spits the output via STDOUT.

$tags = <>;
chomp $tags;
@tags = split(/,/, $tags);

$values = <>;
chomp $values;
@values = split(/,/, $values);

shift @tags;
$date = shift @values;

(scalar @tags == scalar @values) || die "Pairs do not match\n";

for (0..$#tags) {
         print "$date\t$tags[$_]\t$values[$_]\n";
}

Best of luck.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+mbcoeS99pGMif6wRAqIfAKCJJRysroOGPYc5OgvDfyCytmqEJACeMfMh
A9o7WqenB3C0o6GqZvrSVAo=
=MRKD
-----END PGP SIGNATURE-----



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

Date: Sun, 13 Apr 2003 19:46:37 +0100
From: "Ras" <Ras@majere.demon.co.uk>
Subject: Network socket - binary data.
Message-Id: <b7cb16$84b$1$8300dec7@news.demon.co.uk>

I have found lots of examples of how to pass ASCII data via IO sockets, and
its essentially the same as a chat server or webserver...

what i am having a hard time finding data on is how to pass binary data
(many examples state they don't work with binary data, but don't give an
alternative.)

i am trying to move data from one system to another without using FTP.

thanks for anyhelp (and you should print any help on this, as even
commercial books lack this basic example)

Ford





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

Date: 13 Apr 2003 12:40:06 -0700
From: gert.vanderstukken@pandora.be (Gert Vanderstukken)
Subject: Preventing users from ending script + checking admin rights
Message-Id: <5eb4ae79.0304131140.3ba5d13e@posting.google.com>

Hi all,

I am new to Perl and try to find my way through all these available
modules.

In particular I'm looking for a way to hide (or gray out) the
"right-upper corner cross". This way users would be unable to stop a
running script while it's doing his work.
I allready checked the Win32::Console module, but nothing in here.

Second question: I want to check if the user has administrative rights
on his PC(NT) before the scripts continues. I tried Win32::NetAdmin
and it is promising, but unfortunately: it will not traverse domains.
All PC's in here are member of the resource domain X, while user
accounts are created in account domain Y (domain X trusts domain Y).
So the user his (or here) account is not allways directly a member of
the local administrators group. It can be that it is in a group on
domain Y, while this group is member of the local administrators
group. One solution would be to check all groups that are member of
the local administrator group, but I guess there must be a better way.
Did anybody already came acros this problem?

Thanks for helping me out...

Gert Vanderstukken
Leuven
Belgium


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

Date: Sun, 13 Apr 2003 03:45:08 -0700
From: "Sha Sha" <shasha1980@hotmail.com>
Subject: Return value from perl module
Message-Id: <b7bf3l$t6k$1@news.Stanford.EDU>

Hi,

I'm attempting to package this perl code
(http://www.worldatwar.org/photos/exif/) which reads EXIF data from JPEG
images into a module for use within Movable Type. I'm an experienced
programmer, but I've had very little experience with perl, so this is all a
little new to me. I've been using the Movable Type code as examples, so I'm
not sure whether I'm doing things correctly.

In EXIF.pm, I have a function readEXIF which reads in the EXIF data and
returns the timestamp as a string.
So I have something like this:

package EXIF;
use strict;
use Exporter;
use vars qw ( @EXPORT_OK );
@EXPORT_OK = qw( readEXIF );
 ...
sub readEXIF {
   my ($datetime);
   ...
   $datetime = [call sub to read and return EXIF data];
   printf "Date and time is %s\n", $datetime;
   return $datetime;
}

Then I made a little test script that uses the package:
#!/usr/local/bin/perl

use EXIF qw( readEXIF );

my $test = EXIF::readEXIF("testphoto.jpg");
printf "test is $s\n", $test;

The output of my test script is:
Date and time is 2003:03:25 12:09:59
test is

So I know that the readEXIF is being called and that the correct timestamp
is being read, but it's not being returned to my test script. Is there
something I need to do to return the value correctly?

Thanks,
Sha Sha




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

Date: Sun, 13 Apr 2003 03:54:18 -0700
From: "Sha Sha" <shasha1980@hotmail.com>
Subject: Re: Return value from perl module
Message-Id: <b7bfkr$15$1@news.Stanford.EDU>

Apologies; I was returning the value correctly, just not *printing* it
correctly.

printf "test is $s\n", $test;
should have been:
printf "test is %s\n", $test;

Let's hear it for typos.

-Sha Sha




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

Date: 13 Apr 2003 08:39:16 -0700
From: massion@gmx.de (FMAS)
Subject: search with unicode charaters
Message-Id: <f0b3f4c9.0304130739.3760b2ca@posting.google.com>

Hi,

This is a newbie question but I have a script with a search function
which works well on ASCII files and not on Unicode files:

use UCD; # I tried also utf8
(...)
foreach $line(@file) {
	
	chomp $line;

	if ($line =~ m/&#27700;&#27744;&#20013;&#28040;&#27602;/i) { 

(...)

I need to save my script in unicode format otherwise I cannot enter
the search string. When I do this I get a lot of error messages
because the code is not recognized (e.g. "Missing semicolon on
previous line?" etc).

Any suggestions?

Francois


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

Date: Sun, 13 Apr 2003 10:30:23 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Shortcut
Message-Id: <3%ama.11301$U34.1293@nwrddc02.gnilink.net>

William Alexander Segraves wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:gC4ma.1549$ok3.1406@nwrddc03.gnilink.net...
>> Joe Creaney wrote:
>>> what is the shortcut for swapping likew this this I can't seem to
>>> find it.
>>>
>>> $c = $a;
>>> $a = $b;
>>> $b = $c;
> <snip>
>> If you care about $c, too, then
>>     ($a, $b, $c) = ($b, $a, $a);
>
> Jue, I think the OP may be simply trying to rotate the elements of
> the array ($a,$b,$c) cyclicly by moving the third element to the
> first position, e.g.,
[...]

The OP said "swapping" and his code uses the classic way of doing it:
swapping the values of the two variables $a and $b by using a temporary
third variable $c (which is a poor choice in naming, $tmp would have made
his intentions clearer). And he was asking for a simpler way to do this,
i.e. how to swap $a and $b without the use of a third variable. A very
classic problem that cannot be solved in e.g. C, Pacal, or Modula.

Depending upon if $c was really only a temporary auxiliary variable or if it
is being used later the OP could use either of my two suggestions, the
2-variable swap (which you snipped) or the 3-variable swap above which has
exactly the same semantic as his original code, including the same final
value for $c.

> Perhaps we have not interpreted the OP's problem the same way? Or
> maybe I don't understand what you were trying to do?

Your interpretion of "swapping" as "cycling/rotating" is interesting but
doesn't match the original code and the OP mentioned nowhere that he want to
cycle/rotate elements or that his code doesn't work as intended.

I'm assuming the OPs code does what he wants it to do but he is looking for
a "better" way to do it.
You are assuming the OPs code does not do what he wants it to do and you are
guessing what the OP might have wanted instead.

jue




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

Date: Sun, 13 Apr 2003 12:31:29 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Shortcut
Message-Id: <b7c72p$l20$1@slb0.atl.mindspring.net>

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:3%ama.11301$U34.1293@nwrddc02.gnilink.net...

> Your interpretion of "swapping" as "cycling/rotating" is interesting but
> doesn't match the original code and the OP mentioned nowhere that he want
to
> cycle/rotate elements or that his code doesn't work as intended.
>

Thanks for your kindness. Let's look at the original problem statement and
code:

    what is the shortcut for swapping likew this this I can't seem to find
it.

    $c = $a;
    $a = $b;
    $b = $c;

From your analysis, I believe you interpreted  this as

    $tmp = $a;
    $a = $b;
    $b = $tmp;

If the OP had simply stated "swapping $a and $b likew this" instead of
"swapping likew this", his intent would have been clear.

> I'm assuming the OPs code does what he wants it to do but he is looking
for
> a "better" way to do it.

Yes, from the word "Shortcut" in the subject, I should have noted that
"shorter", not
"better" was the objective.

> You are assuming the OPs code does not do what he wants it to do and you
are
> guessing what the OP might have wanted instead.

Guilty as charged. ;-)

Thanks for the clarifications.

Cheers.

Bill Segraves








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

Date: Sun, 13 Apr 2003 13:17:40 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: Shortcut
Message-Id: <3E99A9C4.8070903@annuna.com>



Bob Walton wrote:
> Joe Creaney wrote:
> 
>> what is the shortcut for swapping likew this this I can't seem to find 
>> it.
>>
>> $c = $a;
>> $a = $b;
>> $b = $c;
>>
> 
> ($c,$a,$b)=($a,$b,$c);
> 
> except that will preserve the original contents of $c, where your code 
> above will lose it.
> 

No I want to swap a and b I don't care about c it is just a holder.

($a) = ($b) will swap values?









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

Date: Sun, 13 Apr 2003 18:45:23 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Shortcut
Message-Id: <mbudash-CA640C.11452413042003@typhoon.sonic.net>

In article <3E99A9C4.8070903@annuna.com>, Joe Creaney <mail@annuna.com> 
wrote:

> Bob Walton wrote:
> > Joe Creaney wrote:
> > 
> >> what is the shortcut for swapping likew this this I can't seem to find 
> >> it.
> >>
> >> $c = $a;
> >> $a = $b;
> >> $b = $c;
> >>
> > 
> > ($c,$a,$b)=($a,$b,$c);
> > 
> > except that will preserve the original contents of $c, where your code 
> > above will lose it.
> > 
> 
> No I want to swap a and b I don't care about c it is just a holder.
> 
> ($a) = ($b) will swap values?

no:

($b, $a) = ($a, $b);

or:

($a, $b) = ($b, $a);

hth-

-- 
Michael Budash


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

Date: Sun, 13 Apr 2003 20:36:46 +0100
From: "Cybergrafx" <cybergrafx@hotmail.com>
Subject: Re: Shortcut
Message-Id: <b7ce9a$rr2$1@news6.svr.pol.co.uk>

Hi Joe,

"Joe Creaney" <mail@annuna.com> wrote in message
news:3E98C47C.9080609@annuna.com...
: what is the shortcut for swapping likew this this I can't seem to find it.
:
: $c = $a;
: $a = $b;
: $b = $c;
:

Maybe you're trying to recall this:-

my $a = 'a';
my $b = 'b';

$a ^= $b;
$b ^= $a;
$a ^= $b;

print "$a $b";

(Something us old assembly level programmers would do when we ran out of
registers).

I wouldn't like to suggest that there was any efficiency gain in Perl
though...

Ted




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

Date: Sun, 13 Apr 2003 19:52:15 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Shortcut
Message-Id: <x7znmudvkg.fsf@mail.sysarch.com>

>>>>> "C" == Cybergrafx  <cybergrafx@hotmail.com> writes:

  C> Maybe you're trying to recall this:-

  C> $a ^= $b;
  C> $b ^= $a;
  C> $a ^= $b;

not too good if those are strings of different lengths. the shorter will
get padded with null bytes and the results will all have the same length
which isn't the same as a clean swap.

  C> I wouldn't like to suggest that there was any efficiency gain in Perl
  C> though...

or any correctness gain. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 13 Apr 2003 21:17:10 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Shortcut
Message-Id: <slrnb9jkum.a4j.abigail@alexandra.abigail.nl>

Uri Guttman (uri@stemsystems.com) wrote on MMMDXII September MCMXCIII in
<URL:news:x7znmudvkg.fsf@mail.sysarch.com>:
:) >>>>> "C" == Cybergrafx  <cybergrafx@hotmail.com> writes:
:)  
:)   C> Maybe you're trying to recall this:-
:)  
:)   C> $a ^= $b;
:)   C> $b ^= $a;
:)   C> $a ^= $b;
:)  
:)  not too good if those are strings of different lengths. the shorter will
:)  get padded with null bytes and the results will all have the same length
:)  which isn't the same as a clean swap.


And even worse if the scalars are references.


Abigail
-- 
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`; 


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

Date: 13 Apr 2003 04:34:45 -0700
From: bruno@Skorepa.com (Bruno Skorepa)
Subject: Re: split question
Message-Id: <59f4f754.0304130334.38771923@posting.google.com>

Thanks for all the hints,
I really appreciated that.

Bruno.


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

Date: Sun, 13 Apr 2003 15:19:03 -0500
From: Joe Creaney <mail@annuna.com>
Subject: What is wrong?
Message-Id: <3E99C637.8080506@annuna.com>

Here is a snippet of a program I am writing and trying to debug.  It is 
a simple role-playing game.  I am using objects and packages.  Right now 
the compiler is giving my syntax errors in my package declaration 
statements as marked.  I am very sure that they are not wrong but I 
would like some advice for finding where the errors relay are.




generate {

my ($player, $mx, $my) = @_;
my $v;
my @mm;
my $hp;
my @num;
my $lp = 0;
my $rm;
my $x;

my @ml = (
	[ "Rat",1,0,2,9,10 ],
	[ "Kobold",1,0,4,9,10 ],
         [ "Orc",1,0,6,8,15 ],
	[ "Skelliton",1,0,4,9,10 ],
         [ "Gobblin",1,0,7,4,10 ],
         [ "Hobgobblin",2,0,6,6,15 ],
      	[ "Wolf",2,0,6,5,20 ],
	[ "Ogre",3,0,7,5,25 ],
	[ "Troll",3,0,8,4,25 ],
	[ "Giant",3,0,3,4,8,30 ],
         [ "Dragon!",4,0,10,1,100 ],
          );

# 0 name,1 Hit dice (Level),2 Hit Points,3 Max dammage,4 Armor Class,5 
Expewrience value

$rm = int(rand(4)) + $player->{lv};
if ($rm > 10 )
         {$rm = 10; }

@mm = @ml[$rm];

for ($x=0; $mm[1]; $x++) {
         $hp += int(rand(6))+1;
         }

print "You see a $mm[0] \n";

$mm[2] = $hp;
while  ($num[$lp]->name ne " "){
	if ($num[$lp]->{name} eq " ") {
	$num[$lp] =  new (@mm, $mx, $my );
	$lp++;
		}
	}
$v = $num[$lp];
return $v, $player;

}

package Map;      <-----Error
#!/usr/bin/perl -w


new {
	my @map1 = (
         [ qw (# # # # # # # # # # # # # # # # #)],
         [ qw (# . . . . # . . . . # . # # . # #)],
         [ qw (# # # # . # . # # . # . # . . . #)],
         [ qw (# . . . . . . . # . # . # . # . #)],
         [ qw (# . . # # . # # # . . . # . # . #)],
         [ qw (# . . # . . . # # . # . # . # # #)],
         [ qw (# # . # # # . . . . # . . . . . #)],
         [ qw (# # . . # . . # # # # # # # # . #)],
         [ qw (# # # # # # # # # # # # # # # X #)],
	);
	my $map = {
		map => @map1
		};
	bless $map;
	return $map;			
	}


package Main;      <----Error
#!/usr/bin/perl -w
use strict;

my $name;



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

Date: Sun, 13 Apr 2003 13:15:47 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Re: What is wrong?
Message-Id: <3E99A953.6030901@annuna.com>

This is just a snipit,  I figured that the error is above my lines.  I 
don't see any errors I wondered if with telling the error I could get 
some advice on where to look.  There is a correction that isn't my 
package main it is another pachage.

Jürgen Exner wrote:
> Joe Creaney wrote:
> 
>>What is wrong here, I get a syntax error here at my package main then
> 
> 
> Why don't you just read(!) what the error message says:
>     "Unmatched right curly bracket at ....."
> 
> 
>>it says not BEGIN not safe after errors
>>
>>Here is my code.
>>
>>$mm[2] = $hp;
>>while  ($num[$lp]->name ne " "){
> 
> 
> Open one
> 
> 
>>if ($num[$lp]->{name} eq " ") {
> 
> 
> Open two
> 
> 
>>$num[$lp] =  new (@mm, $mx, $my );
>>$lp++;
>>}
> 
> 
> Close one
> 
> 
>>}
> 
> 
> Close two
> 
> 
>>$v = $num[$lp];
>>return $v, $player;
>>
>>}
> 
> 
> Close three????
> 
> 
>>package Map;  <-- Error here
> 
> 
> No, it's the line above
> 
> 
>>#!/usr/bin/perl -w
>>use strict;  <-- Error here
> 
> 
> Really? My compiler doesn't even get that far.
> 
> 
>>new {
> 
> 
> jue
> 
> 



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

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


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