[27108] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8985 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 22 21:05:42 2006

Date: Wed, 22 Feb 2006 18:05:05 -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           Wed, 22 Feb 2006     Volume: 10 Number: 8985

Today's topics:
    Re: Alternate for buzzers in a competition (Raghuramaiah Gompa)
    Re: DBD::CSV malfunction? xhoster@gmail.com
        Error when trying to print to a file and locking <rbutcher.nospam@hotmail.com>
    Re: Error when trying to print to a file and locking <1usa@llenroc.ude.invalid>
        error-prone coding styles <samwyse@gmail.com>
    Re: Reading Mac / Unix / DOS text files (Rick Scott)
    Re: savely change permission and group on files <daleif@imf.au.dk>
    Re: savely change permission and group on files <abigail@abigail.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Feb 2006 00:30:38 +0000 (UTC)
From: rgompa@steel.ucs.indiana.edu (Raghuramaiah Gompa)
Subject: Re: Alternate for buzzers in a competition
Message-Id: <dtivne$emd$1@rainier.uits.indiana.edu>

In article <Xns97717464CD60Eebohlmanomsdevcom@130.133.1.4>,
Eric Bohlman  <ebohlman@omsdev.com> wrote:
>xhoster@gmail.com wrote in
>news:20060221093513.732$wa@newsreader.com:
>
>> rgompa@steel.ucs.indiana.edu (Raghuramaiah Gompa) wrote:
>>> We are hosting a math fair. We have teams competing.
>>> I am just wondering whether there is anyway we could use
>>> laptops to serve as buzzers.  Laptops can be connected to
>>> a central computer through wireless.  Team can press a
>>> button when they are ready.  Can we write a perl code to
>>> do this on the computers?  Please help. .. Raghu
>> 
>> Yes.  See IO::Socket::INET and IO::Select.
>
>That was my first thought too, but then I realized a
>simpler way would be 
>just to set up an HTTP server on the central computer
>and run a CGI script 
>that would deliver a very simple HTML form to each
>laptop and then record 
>when each submit button was pressed.  That way you
>don't need to write 
>client software for the laptops.


Thank you so much for all suggestions.  I will try to  
answer some of 
the questions posted about my post. 

I am new to perl, but I am making progress.  I have been 
learning so much from this group.  Thanks a lot.

I wanted to know whether perl code can be used to solve 
the solving - I wanted to know such a code already exists 
- I wanted to know whether it is feasible.

It seems using a webpage would be optimal.  I would have 
to read more to actually understand thoroughly.  But this 
gives me a direction to pursue.  Thank you so much.  .. 
Raghu


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

Date: 23 Feb 2006 01:04:55 GMT
From: xhoster@gmail.com
Subject: Re: DBD::CSV malfunction?
Message-Id: <20060222200726.767$2A@newsreader.com>

Mark <Mark.Fenbers@noaa.gov> wrote:

> my $dbstr = 'DBI:CSV:f_dir=data';
> my $dbh = DBI->connect($dbstr,undef,undef,{ChopBlanks => 1,PrintWarn =>
>         1,PrintError => 0}) or warn "Cannot connect to: $dbstr: " .
>         DBI->errstr;

You ask us for help without even asking DBI for help first?  That is
insulting.

PrintError => 1

> my $sql = "SELECT * FROM location ORDER BY lid;";

valid SQL does not have a trailing ;

Xho

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


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

Date: Thu, 23 Feb 2006 00:20:32 GMT
From: "Robert" <rbutcher.nospam@hotmail.com>
Subject: Error when trying to print to a file and locking
Message-Id: <kd7Lf.61549$sa3.48710@pd7tw1no>

Hi,

I am getting the following error when trying to print to a file and locking.
Browser Error:

------------------
Bareword "LOCK_EX" not allowed while "strict subs" in use at record.pl line
208.
Execution of record.pl aborted due to compilation errors.
------------------

Here is my write-to-file code:

------------------
sub record {

my $nowtime = time();
my $newentry = "$nowtime|$invoice|$fullname|$company|$emailaddy|$phone";

open (LOCKER, "<lockfile.db") or die "Can't open file: $!";
flock (LOCKER, LOCK_EX) or die "Can't lock file: $!";

open (FH, ">>records.db") or die "Can't open file: $!";
  print FH "$newentry\n";
close(FH);

close(LOCKER);

}
------------------

I always use "use strict;" in my programs and have never seen this error
before. I'm not sure where to start in researching a solution. Please if you
have any thoughts please and thank you.

Robert




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

Date: Thu, 23 Feb 2006 00:25:34 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Error when trying to print to a file and locking
Message-Id: <Xns9772C5B692026asu1cornelledu@127.0.0.1>

"Robert" <rbutcher.nospam@hotmail.com> wrote in
news:kd7Lf.61549$sa3.48710@pd7tw1no: 

> I am getting the following error when trying to print to a file and
> locking. Browser Error:
> 
> ------------------
> Bareword "LOCK_EX" not allowed while "strict subs" in use at record.pl
> line 208.
> Execution of record.pl aborted due to compilation errors.

Hmmm ... Have you considered reading

perldoc -f flock

especially the part:

 OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly
 combined with LOCK_NB. These constants are traditionally valued
 1, 2, 8 and 4, but you can use the symbolic names if you import
 them from the Fcntl module, either individually, or as a group
 using the ':flock' tag. 

> ------------------
> 
> Here is my write-to-file code:
> 
> ------------------
> sub record {
> 
> my $nowtime = time();
> my $newentry =
> "$nowtime|$invoice|$fullname|$company|$emailaddy|$phone"; 
> 
> open (LOCKER, "<lockfile.db") or die "Can't open file: $!";
> flock (LOCKER, LOCK_EX) or die "Can't lock file: $!";

Have you considered reading:

perldoc -f flock

especially the part:

    Note that the fcntl(2) emulation of flock(3) requires that
    FILEHANDLE be open with read intent to use LOCK_SH and requires
    that it be open with write intent to use LOCK_EX.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Thu, 23 Feb 2006 01:45:43 GMT
From: Samwyse <samwyse@gmail.com>
Subject: error-prone coding styles
Message-Id: <bt8Lf.36595$F_3.17459@newssvr29.news.prodigy.net>

Rick Scott wrote:
> (January Weiner <january.weiner@gmail.com> uttered:)
> 
>>Rick Scott <rick@shadowspar.dyndns.org> wrote:
>>
>>>Given that it reduces the comprehensibility of your program and
>>>that you could have used any number of more legible identifiers,
>>>I'd call use of `IF' poor style, if not an outright error.
>>
>>Why an error? (yeah, it can lead to errors, agree, but then, of
>>course, a collegue of mine says the same about using Perl)
> 
> Why cause a greater propensity to introduce errors than one has to?

One of the very first programs (non-Perl) that I had to maintain (as 
opposed to create) was written by a joker who decided to use O as a 
variable name.  Distinguishing between
   X = 0;
and
   X = O;
was a source of much merriment for the rest of the staff.  Fortunately 
for his nose, he was quick at ducking whenever clenched fists were in 
his vicinity.


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

Date: Thu, 23 Feb 2006 01:37:36 -0000
From: rick@shadowspar.dyndns.org (Rick Scott)
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <1a69.43fd11e0.6c983@shadowspar>

(January Weiner <january.weiner@gmail.com> uttered:)
> Rick Scott <rick@shadowspar.dyndns.org> wrote:
> > Your filehandle `IF' collides with Perl's conditional `if' in
> > the mental hash-bucket of the programmers who have to read
> > your code.
>
> That's an argument. I will refrain from using <IF> in public. It
> causes too much stir and excites people.
>
> > Given that it reduces the comprehensibility of your program and
> > that you could have used any number of more legible identifiers,
> > I'd call use of `IF' poor style, if not an outright error.
>
> Why an error? (yeah, it can lead to errors, agree, but then, of
> course, a collegue of mine says the same about using Perl)

Why cause a greater propensity to introduce errors than one has to?


> > On the contrary -- I would posit that any coding practice that
> > makes it easier to inadvertently introduce bugs into your
> > program is a poor one. By using a bareword filehandle, you're
> > essentially using a package variable (*IF). If some other piece
> > of code in the same package namespace touches that bareword
> > while you're using it to read from a file, your filehandle will
> > get stomped and your code will break without you even having
> > changed it. That's why it's a bad idea.
>
> I think this depends a little on what you are using Perl for, and
> just some basic common sense is sufficient to say when using
> shorthand is OK and when it is a bad idea. I do use the <IF>
> construct in few-liners that do not read more than one file. I do
> think it is important to define variables if you are writing a
> larger piece of code. I do not understand the whole stir about
> this issue.

Since there's a way to do things that lets you do everything you can 
do with a bareword filehandle without incurring the disadvantages,
why not make a habit of using it?  As of Perl 5.6, you can do this:

    open my $FILE, '<', $filename or die "Can't open file: $!";

Then the filehandle is stored in the lexical variable $FILE (where it
can't be stomped on by someone else's code) instead of in the package 
variable *FILE (where it can).


> > Pick up a copy of Damian Conway's "Perl Best Practices" -- he
> > explains why this and about a thousand other `harmless style
> > preferences' aren't harmless, aren't stylish, and definitely
> > aren't preferable.
>
> So what is the problem with whitespace? Why is while(<STDIN>) more
> harmful than while ( <STDIN> ) ?

Actually, I'd go with the first of these two.  About whitespace in 
general -- there's not necessarily too many hard and fast rules;
you just want to make best use of it to increase the readability of
your code.  To take an extreme example,

LINE: 
foreach my $line (@lines) {
    my ($registry, $cc, $type, $start, $length, $date, $status) =
        split qr{\|}, $line;

    next LINE unless $status;
    next LINE unless ($type eq 'ipv4');

    print $start;
}

is obviously much better than

LINE:foreach my $line(@lines){my($registry,$cc,$type,$start,$length,$date,$status)=split qr{\|},$line;next LINE unless $status;next LINE unless($type eq 'ipv4');print$start;}

or 

LINE:
foreach
my 
$line
(
@lines
)
{
my
($registry,
$cc,
$type,
$start,
$length,
$date,
$status)
=
split
qr{\|}
,
$line
;
 ...

or some other godawful thing.




Rick
-- 
key CF8F8A75 / print C5C1 F87D 5056 D2C0 D5CE  D58F 970F 04D1 CF8F 8A75 
Humankind cannot bear very much reality.
     :Karen Armstrong


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

Date: Thu, 23 Feb 2006 01:14:50 +0100
From: Lars Madsen <daleif@imf.au.dk>
Subject: Re: savely change permission and group on files
Message-Id: <43fcfe5c$0$11674$ba624c82@nntp02.dk.telia.net>


> Huh? I don't get it. Why would you be vulnerable if you're doing something
> simple as changing the permissions of files?
> 

if one (by mistake) runs sys commands on unchecked data

as in doing a naive delete of a file named '-rf /'


/daleif


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

Date: 23 Feb 2006 00:16:58 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: savely change permission and group on files
Message-Id: <slrndvpvnq.h1.abigail@alexandra.abigail.nl>

Lars Madsen (daleif@imf.au.dk) wrote on MMMMDLIX September MCMXCIII in
<URL:news:43fcfe5c$0$11674$ba624c82@nntp02.dk.telia.net>:
??  
?? > Huh? I don't get it. Why would you be vulnerable if you're doing something
?? > simple as changing the permissions of files?
?? > 
??  
??  if one (by mistake) runs sys commands on unchecked data

If you are afraid you make mistakes like that, you shouldn't program
at all. There's no defence.

??  as in doing a naive delete of a file named '-rf /'


Huh? A native delete of a file in Perl is quite safe, and spelled 'unlink'.



Abigail
-- 
               split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_)  {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


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

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


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