[18012] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 172 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 30 00:05:52 2001

Date: Mon, 29 Jan 2001 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980831107-v10-i172@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 29 Jan 2001     Volume: 10 Number: 172

Today's topics:
        'Code Review' Requested (CGI/DBI/DBD::CSV/Storable) <nospam@nospam.com>
        <>, tie *STDIN or *ARGV <johnlin@chttl.com.tw>
    Re: A simple question about using Braces <rick.delaney@home.com>
    Re: A simple question about using Braces (Damian James)
    Re: accessing name of variable <rick.delaney@home.com>
        code review request <shutupsteve@aNwOdSaPnAgM.com>
    Re: Finding unused variables ? <rick.delaney@home.com>
    Re: how do I use 'strict' and 'vars' <extramail@home.com>
    Re: How to export functions from a module? (newbie-ish  <rick.delaney@home.com>
        need to extract Subject: xxxxxx from incoming email to  <robert@chalmers.com.au>
    Re: New Perl Book. <bowman@montana.com>
    Re: Newbie Question:  Can I compile a Perl Script? <carvdawg@patriot.net>
        perl and embedded systems. <shuo.lin@sita.int>
        Printing to a device, not a local port? <karlt@pine-grove.com>
    Re: Printing to a device, not a local port? <chrisw@dynamite.com.au>
    Re: Printing to a device, not a local port? <chrisw@dynamite.com.au>
    Re: Seeking timezone conversion advice <peter.sundstrom@eds.com>
    Re: Seeking timezone conversion advice <time4tea@monmouth.com>
    Re: Using Braces <shutupsteve@aNwOdSaPnAgM.com>
    Re: Using Braces jlamport@calarts.edu
    Re: Win32ChangeNotify problems w/WinNT while Win98 is O <carvdawg@patriot.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 30 Jan 2001 02:05:06 GMT
From: The WebDragon <nospam@nospam.com>
Subject: 'Code Review' Requested (CGI/DBI/DBD::CSV/Storable)
Message-Id: <9557gi$kv9$0@216.155.32.51>

After checking with one of the regulars here, I have decided to post a 
request for a 'review by peer' of a recent update/overhaul to a program 
that you all helped me learn enough to write. 

The overhaul produced a MUCH cleaner code-base; so much so that my 
adding the sort-by-size routines to the recent update took me < 2 
minutes to complete AND test. 

I still feel that there MUST be ways that I can do this 
better/faster/more efficiently, etc, and thus would like to invite your 
comments on the following code 

I've put this into an HTML page set between <PRE></PRE> tags to retain 
the formatting as posting it here would cause a mess of line-wrapping, 
plus the code itself is around 6 pages. 

    <http://216.155.0.50/~sgodin/misc/codesample.htm>

your comments would be extremely welcome.

And thank you again, one and all, for enabling me to absorb and learn 
Perl as rapidly as I have done.

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Tue, 30 Jan 2001 11:06:04 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: <>, tie *STDIN or *ARGV
Message-Id: <955b62$ll5@netnews.hinet.net>

Dear all,

I try to provide a package that change the behavior of <> :
when (and only when) <> needs to input from console, pop up a
Tk dialog to ask for user input.

I read the document about <>.  It will open from @ARGV or
set @ARGV to ('-') and open, then becomes equivalent to <ARGV>.
So I think I should either tie *ARGV or tie *STDIN.

In the following program, my intension is:
when @ARGV is provided, print those files in @ARGV as normal
otherwise, when <> (originally) gets input from console, feed in

line 1
line 2
line 3

for it to print.

Note that all the magics should be done in the package.
The main program should not be changed except for adding 'use A'.
----------------------------------------------------------------
package A;

sub TIEHANDLE { print "tie called\n"; bless \(my $num = 0) }

sub READLINE {
    my $num = shift;
    $$num++ < 3? "line $$num\n": undef;
}

BEGIN { tie *ARGV,'A' }

package main;

$| = 1;
while(<>) { print }
----------------------------------------------------------------
The result is: no matter @ARGV is empty or not, it prints
line 1
line 2
line 3

Well, let's try

BEGIN { tie *STDIN,'A' }

The result is: no matter @ARGV is empty or not, it waits for
input from the console.

Hmm... What's the modification I need here?

Thank you.

John Lin






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

Date: Tue, 30 Jan 2001 03:00:56 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: A simple question about using Braces
Message-Id: <3A7631AF.15EE6F6C@home.com>

[posted & mailed]

Vik wrote:
>  
> $sql=q{select sysdate from dual};
> 
> Looking at the camel book, it
> seems that the q adds single quotes to the select statement. But what is 
> not clear to me is the use of { }. Why braces??

Why not?  :-)

Look up q/STRING/ in perlop.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 30 Jan 2001 03:02:11 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: A simple question about using Braces
Message-Id: <slrn97cbm6.7qh.damian@puma.qimr.edu.au>

Thus spake Vik on Mon, 29 Jan 2001 17:53:41 -0800:
>...
>$sql=q{select sysdate from dual};
>
>I put this in a script by itself followed by a print $sql statement and ran
>it. It echoed the select statement back at me. Looking at the camel book, it
>seems that the q adds single quotes to the select statement. But what is not
>clear to me is the use of { }. Why braces??
>

You should examine the perlop manual page, and look again at the section
under "Quote and  Quote-like Operators" (and indeed, re-read the bit you just
mentioned in the Camel book).

The above is equivalent to saying

	$sql='select sysdate from dual';

which likewise will not include the single quotes. Using 'q' or 'qq' will
not add single or double quotes to the string, they are alternative 
representation for these characters. In other words, you probably wanted:

	$sql=q{'select sysdate from dual'};

The advantage being that you avoid needing to escape the single quotes
inside the string. The braces are an arbitrary choice, as you'll see when
you re-check the docs.


However, if you are using DBI, please note that trying to pass a string 
containing (additional) quotes will break if you try to do it this way! 
You should instead investigate the $database_handle->quote() method provided 
by DBI, and also the auto-escaping behaviour of placeholders. 

HTH,

Cheers,
Damian
-- 
#requires 5.6.0 ## my first attempt at one of these...
$;=ord$%,$:=$;-ord q,.,,$_=q,3346:3366:3276:3326:3386:546:566:966:3396:3376:,.
q,3386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:3266,.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$;-$:,eg,s,$;,chr$&-$:,eg,
eval eval;


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

Date: Tue, 30 Jan 2001 02:50:58 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: accessing name of variable
Message-Id: <3A762F4E.6E0C91DE@home.com>

[posted & mailed]

Jörg Ziefle wrote:
> 
> Just curious:
> 
> Is it possible (with globs, ...) to directly access the name of a
> variable?  For instance, when I have a scalar named $foo, the operation
> would give me the string 'foo', that is, the name of $foo stringified.

Have you tried 

   print *foo;

It's close enough that you might want to try working with that.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 30 Jan 2001 03:53:21 GMT
From: "Stephen Deken" <shutupsteve@aNwOdSaPnAgM.com>
Subject: code review request
Message-Id: <RUqd6.84153$lV5.1623409@news2.giganews.com>

Hi all,

Short version of the below: I'd like a code review of the attached code,
just to make sure there are no glaring errors or major security holes.  If
this is unwelcome, please feel free to flame me at will.

I didn't get a reply to the previous message, and it's not showing up on
some other newsfeeds, so I'm guessing that most servers discarded it because
it had an attachment.  Just as well, actually, because I've improved it
slightly since then.

I've written the following program to handle email.  I've got a large number
of users (~3000) in a database, and currently I'm routing email by
manipulating /etc/virtusertable and rebuilding it as new users get added, or
as old users change their preferences.  At this time there are three
possible preferences: 'fwd', which forwards the email to an address; 'web',
which means the user is using webmail; and 'none', meaning the user has
decided not to take advantage of email altogether (some might say, that's a
wise idea ;).

I updated sendmail.cf to add a header called X-Intended-Recipient which,
rather obviously, contains the email address of the intended recipient.
This script looks for that header, grabs the username, looks up the username
in the database, decides what to do with the email, and then does it,
logging all the while.  Since there's no checking to see what addresses the
user is sending mail to, when the script forwards a message it adds a header
called X-Email-Router-Iteration which has a number which signifies the
number of times the message was seen.  If the number is greater than a
threshold, the message is bounced back to the sender.

The source is attached.  I've tested this pretty thoroughly, but any
comments are welcome and very much appreciated.

Thanks,

Stephen Deken.

==================================================

#!/usr/bin/perl -wT

# email-route.pl
# route email to correct location

BEGIN
{
  use strict;

  push( @INC, '/home/web/cgi' );
  require 'common-functions.lib';

  $ENV{'PATH'} = '/usr/lib';
}

my $DEBUG = 1;
my $MAX_ITERATION = 10;
open( LOG, '>>/home/web/cgi/email-route.log' ) if (defined $DEBUG);

END
{
  close( LOG ) if (defined $DEBUG);
}

# declare some variables
my $iteration = 1;
my $username;
my %USER;

# Parse the letter
foreach my $line (<>)
{
  $line =~ tr-\n\r--d;
  if ($line =~ /^X-Email-Router-Iteration: (\d+)$/)
  {
    $iteration = $1 + 1;
    next;
  }
  if ((not defined $username) and ($line =~ /^X-Intended-Recipient:
(\<|)([\w-\d]+)\@myhost\.com(\>|)$/))
  {
    $username = $2;
    next;
  }
  push( @arr, $line . "\n" );
}

check_iteration();

if (defined $username)
{
  logger( "Got letter for '$username'." );
  if (userexists( $username ))
  {
    logger( '  User exists.' );
    %USER = getuserinfo( $username );
    $USER{'emailpref'} = 'fwd' if (not defined $USER{'emailpref'});
    if ($USER{'emailpref'} eq 'web')
    {
      # user has selected webmail option
      logger( '  Adding message to webmail spool.' );
      open( FILE, ">>/home/web/home/$username/.mail" );
      foreach my $line (@arr)
        { print FILE $line; }
      close( FILE );
    }
    elsif ($USER{'emailpref'} eq 'none')
    {
      # user has turned off email support
      logger( '  User has disabled email.' );
      bounce_message( $username );
    }
    else
    {
      # user has bad config or is set to 'fwd'
      # forward the letter to the destination
      if (defined $USER{'email'})
      {
        logger( "  Forwarding letter to '$USER{'email'}'." );
        if (open( MAIL, "| /usr/lib/sendmail -i $USER{'email'}" ))
        {
          print MAIL shift( @arr ); # top header line
          print MAIL "X-Email-Router-Iteration: $iteration\n";
          print MAIL "X-Intended-Recipient: $USER{'email'}\n";
          foreach my $line (@arr)
            { print MAIL $line; }
          close( MAIL );
          if ($?)
          {
            # there was a problem, try later
            logger( '  Delivery failed, deferring...' );
            exit( 75 );
          }
          else
          {
            # successfully delivered
            logger( '  Successfully delivered.' );
            exit( 0 );
          }
        }
        else
        {
          logger( '  ?! could not start sendmail?!' );
          defer_delivery( $username );
        }
      }
      else
      {
        logger( '  ?! email address not defined?!' );
        bounce_message( $username );
      }
    }
  }
  else
  {
    logger( '  No such user!' );
    bounce_message( $username );
  }
}
else
{
  # could not find header, or parsing problem
  logger( '  Bad or missing headers!' );
  bad_headers();
}

# -------------------------------------------------------------------------

sub bad_headers
{
  # Bounce the letter because of bad headers
  my ($username) = @_;
  logger( '  Returning the letter...' );
  print '...error message...';
  exit( 65 );
}

sub bounce_message
{
  # Bounce the letter, giving up delivery
  my ($username) = @_;
  logger( '  Returning the letter...' );
  print '...error message...';
  exit( 67 );
}

sub defer_delivery
{
  # defer delivery for right now
  my ($username) = @_;
  logger( '  Deferring delivery...' );
  print '...error message...';
  exit( 75 );
}

sub check_iteration
{
  # Checks to see if the message has been handled too much
  if ($iteration > $MAX_ITERATION)
  {
    # this message has been handled too much!
    logger( "  Iteration greater than $MAX_ITERATION !" );
    print '...error message...'
    exit( 78 );
  }
}

sub logger
{
  my $logmsg = join( "\n", @_ );
  print LOG "[$$.$iteration] " . $logmsg . "\n" if (defined $DEBUG);
}




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

Date: Tue, 30 Jan 2001 02:16:13 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Finding unused variables ?
Message-Id: <3A762731.233D5FD7@home.com>

John Lin wrote:
> 
> One day I found my code can be trimmed cleaner:
> 
> use strict;
> use Exporter;
> use vars '@ISA @EXPORT';
> @ISA = ('Exporter');
> @EXPORT = ('PI');
> 
> becomes
> 
> use strict;
> use base 'Exporter';
> our @EXPORT = ('PI');
> 
> I don't know whether I should thank to "our" or hate "use strict".

strict has never been an issue here, unless you're dynamically assigning
@EXPORT, or have more than one package per file.  Just change the order.

    use base 'Exporter';
    @EXPORT = ('PI');
    use strict;


I have no objections to "our", but its usefulness as anything but a
shortcut for use 'vars' is dubious.  Here are a couple I've used where
use 'vars' probably gives more scope than you'd want:

    while(<>) {
        our ($x, $y) = split;
        #...
        write;
    }

    format STDOUT = 
    ^<<<<<<< ^<<<<<<<<
    our ($x,       $y)
    .

and

    while (my ($key, $ref) = each %hash) {
        our %h;*h = $ref;
        print $h{subkey};# saving on ->s
    }

But most people don't use formats and I'd much rather be able to create
lexical aliases.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 30 Jan 2001 02:18:15 GMT
From: Joel Nelson <extramail@home.com>
Subject: Re: how do I use 'strict' and 'vars'
Message-Id: <3A762434.5B10F249@home.com>

Bart Lateur wrote:

> Well, if you use $::soAndSo for the variable name, strict won't
> complain. The variables themselves will be in package main:: . I think
> it's a good way for them to stand out in the source (you can search for
> them).
>
> --
>         Bart.

Ah!  Thanks for the tip.  I think I will do just that.

Joel



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

Date: Tue, 30 Jan 2001 02:41:35 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to export functions from a module? (newbie-ish question)
Message-Id: <3A762D17.F0BB8D3E@home.com>

[posted & mailed]

John Stumbles wrote:
> 
> package Utils ;
> use strict ;
> require Exporter ;
> my  @ISA    =  qw(Exporter);
> my  @EXPORT = qw(
>     NOW MINUTE HOUR DAY WEEK YEAR MONTH QUARTER
>     ) ;

@ISA and @EXPORT should be package variables; not declared with my.  You
could use our() or use 'vars' to declare them but that would be silly.

  package Utils ;
  require Exporter ;
  @ISA    =  qw(Exporter);
  @EXPORT = qw(
      NOW MINUTE HOUR DAY WEEK YEAR MONTH QUARTER
  );
  use strict;

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Tue, 30 Jan 2001 14:49:57 +1000
From: "Merlin" <robert@chalmers.com.au>
Subject: need to extract Subject: xxxxxx from incoming email to perl prog.
Message-Id: <COrd6.62$V%2.4013@nsw.nnrp.telstra.net>

The following bit of code works fine to extract the incoming From: field,
and stuff it into a To: field, but how can I also extract the actual
contents of the Subject: field and use it. $subject = xxxx kind of thing?
I'm darned if I can get it to work.

any ideas anyone?
thanks
Bob
 ............................

$mailfile = /tmp/mail.txt

while(<STDIN>) {
        if (s/^From: //) {
                s/[\012\015]|^ *//g;  #Remove all CR and LF
                $to = $_;

                open (OUT, "|/usr/sbin/sendmail -oi -t");
                open (IN, $mailfile );

                #Read and display FROM line.
                $_ = <IN>;
                print OUT $_;

                print OUT "To: $to\n";

                while (<IN>) { print OUT $_; }
                close IN;
                close OUT;
        }

}




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

Date: Mon, 29 Jan 2001 21:58:58 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: New Perl Book.
Message-Id: <qRrd6.6512$Uo2.24954@newsfeed.slurp.net>


brian d foy <comdog@panix.com> wrote in message
news:comdog-C8C4E4.16022629012001@news.panix.com...
>
> are you sure it's not a complete rewrite? ;)

If it is, it is not as radical. I still miss the little anecdotes about Job
and his livestock from Camel I.





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

Date: Mon, 29 Jan 2001 22:25:09 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Newbie Question:  Can I compile a Perl Script?
Message-Id: <3A763415.A2E323C@patriot.net>

I would agree with you, Eric...however, "RTFFAQ" is far from such an answer.

Eric Bohlman wrote:

> H C <carvdawg@patriot.net> wrote:
>
> > No.  But many times, particularly for those such as myself who are new to
> > Perl, and for those who may be using only...say....the Win32 platform, for
> > example, a little friendly help may be all that's needed.
>
> Telling someone "a carefully peer-reviewed answer to your question can be
> found in the extensive *completely free* documentation that comes with
> every proper installation of Perl; in fact, it's such a common question
> that's it's been specially indexed to make the answer easy to find"
> strikes me as being within the definition of "a little friendly help."

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: Mon, 29 Jan 2001 21:30:35 -0500
From: Shuo Lin <shuo.lin@sita.int>
Subject: perl and embedded systems.
Message-Id: <fo9c7tkvkapb6npqbli4ee4mjvkngiesdf@4ax.com>

Is there an embedded system with perl?
Thanks/SL@news


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

Date: Tue, 30 Jan 2001 02:29:46 GMT
From: "Karl Thompson" <karlt@pine-grove.com>
Subject: Printing to a device, not a local port?
Message-Id: <uGpd6.192257$w35.34376470@news1.rdc1.nj.home.com>


Hi,

Currently, I'm printing reports using formats and this syntax for printer
selection:

 $Printer = ">lpt1";
 open( EQTYPOSRPT, $Printer ) or die
   "The PRINTER could not be found. \n\n";

But what's the syntax for when the printer isn't attached to a local port?
Specifically it is attached to a HP JetDirect running on an NT network.

TIA,

Karl


--
Karl Thompson
Pine Grove Software
CN 5256 BOX 272
Princeton, NJ 08543   USA
v. 609.730.1430 or 800.242.9192
fax: 609.730.1530
http://www.pine-grove.com
karlt@pine-grove.com






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

Date: Tue, 30 Jan 2001 14:20:27 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Printing to a device, not a local port?
Message-Id: <Drqd6.40$rP4.2085@news0.optus.net.au>

"Karl Thompson" <karlt@pine-grove.com> wrote in message
news:uGpd6.192257$w35.34376470@news1.rdc1.nj.home.com...
>  $Printer = ">lpt1";
>  open( EQTYPOSRPT, $Printer ) or die
>    "The PRINTER could not be found. \n\n";
>
> But what's the syntax for when the printer isn't attached to a local port?

Something along these lines:

#!perl -w
use strict;
open(PRINTER, '> //server/laserjet') || die;
while (<DATA>) {
 print PRINTER $_;
}
close(PRINTER);
__DATA__
Some text
to
print





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

Date: Tue, 30 Jan 2001 14:23:10 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Printing to a device, not a local port?
Message-Id: <auqd6.42$rP4.2177@news0.optus.net.au>

"Chris W" <chrisw@dynamite.com.au> wrote in message
news:Drqd6.40$rP4.2085@news0.optus.net.au...
[snip]
> open(PRINTER, '> file://server/laserjet') || die;

Pardon Outlook Express' braindead munging of my file name.
You need to remove the file: bit that it added  (leaving slash slash server
slash laserjet)




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

Date: Tue, 30 Jan 2001 15:40:51 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Seeking timezone conversion advice
Message-Id: <9559jo$2gl$1@hermes.nz.eds.com>


"James Weisberg" <chadbour@wwa.com> wrote in message
news:UIod6.13898$Sl.606099@iad-read.news.verio.net...
> Hello,
>
>    This isn't strictly a perl question, per se, and I apologize in
> advance for the length, but I'm looking for some advice using perl
> to calculate a timezone offset. Let me start by describing the idea.
> Imagine you have a file with configuration info for four sites in
> different timezones:

[snipped lengthy description and examples]

You might like to consider the Time::Timezone module.  See
http://search.cpan.org/search?dist=Time-modules




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

Date: Mon, 29 Jan 2001 23:55:38 -0500
From: "James Richardson" <time4tea@monmouth.com>
Subject: Re: Seeking timezone conversion advice
Message-Id: <955his$4ei$1@slb7.atl.mindspring.net>


"James Weisberg" <chadbour@wwa.com> wrote in message
news:UIod6.13898$Sl.606099@iad-read.news.verio.net...
> Hello,
>
>    This isn't strictly a perl question, per se, and I apologize in
> advance for the length, but I'm looking for some advice using perl
> to calculate a timezone offset. Let me start by describing the idea.
> Imagine you have a file with configuration info for four sites in
> different timezones:
>

Set TZ to the start timezone, and call timelocal or similar, then set TZ to
the destination timezome, and call localtime.

Probably, at least. But this is broken on some UNIX variants. ( not perl's
fault, the underlying routines cache TZ  )

use Time::Local;
# 00:00 Jan 1 2001
my @start_time = ( 0,0,0,1,0,2001);
$ENV{TZ}= "GMT0BST";
my $time = timelocal(@start_time);
$ENV{TZ}= "EST5EDT";
print scalar (localtime($time));

Sun Dec 31 19:00:00 2000

James






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

Date: Mon, 29 Jan 2001 22:07:28 -0600
From: "Stephen Deken" <shutupsteve@aNwOdSaPnAgM.com>
Subject: Re: Using Braces
Message-Id: <mard6.1747$IK6.10185@news6.giganews.com>

> This may be trivial, but has me stuck. What does the following construct
do
> in perl:
>
> $sql=q{select sysdate from dual};
>
> ... Why braces??

Some statements need braces.  When their wisdom bytes come in it moves all
their other bytes around and the statement gets all crooked.  Braces and a
nice retainer semicolon helps them keep that sleek look.

With some help from our friend man, his friends grep and head, and a few
lead pipes, we can beat the solution out of perlop:

$ man perlop | grep -A 11 ' q/' | head -11
       q/STRING/

       `'STRING''
               A single-quoted, literal string.  A backslash rep­
               resents a backslash unless followed by the delim­
               iter or another backslash, in which case the
               delimiter or backslash is interpolated.

                   $foo = q!I said, "You said, 'She said it.'"!;
                   $bar = q('This is it.');
                   $baz = '\n';                # a two-character string
$

You could have said any one of the following too:

  $sql = q!select sysdate from dual!;
  $sql = q#select sysdate from dual#;
  $sql = q(select sysdate from dual);

Personally I would have just:

  $sql = 'select sysdate from dual';

But I wonder if any of them will actually work, since the SQL statement
doesn't have a semicolon?

--sjd;




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

Date: Tue, 30 Jan 2001 04:11:31 GMT
From: jlamport@calarts.edu
Subject: Re: Using Braces
Message-Id: <955etd$6cf$1@nnrp1.deja.com>

In article <ycpd6.112$mq6.155300@news.pacbell.net>,
  <sysdba@pacbell.net> wrote:
> This may be trivial, but has me stuck. What does the following construct do
> in perl:
>
> $sql=q{select sysdate from dual};
>
> I put this in a script by itself followed by a print $sql statement and ran
> it. It echoed the select statement back at me. Looking at the camel book, it
> seems that the q adds single quotes to the select statement. But what is not
> clear to me is the use of { }. Why braces??

Read the docs a little more carefully.  The "quote like" operators
( q qq qx qw s m tr ) can use *any* set of delimiters you choose.  The
following are all equivalent:

$sql=q{select sysdate from dual};
$sql=q(select sysdate from dual);
$sql=q[select sysdate from dual];
$sql=q<select sysdate from dual>;
$sql=q/select sysdate from dual/;
$sql=q|select sysdate from dual|;
$sql=q!select sysdate from dual!;
$sql='select sysdate from dual';

The brackets have no special significance: they are simply the character
being used to delimit the string literal.

-jason


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 22:25:38 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Win32ChangeNotify problems w/WinNT while Win98 is OK
Message-Id: <3A763432.215BFCFC@patriot.net>

Sorry.  My eyes saw 5 backslashes for some reason...

Dave wrote:

> The backslashes in the path have to be escaped, therefore
> "C:\\\\Timothymarsch\\SHARE" resolves to
> C:\\Timothymarsch\SHARE.
>
> In addition, if there were too many slashes, wouldn't that also
> be the case when I run it under Win98 and it runs correctly?
>
> "H C" <carvdawg@patriot.net> wrote in message
> news:3A76034E.B3CBDD1E@patriot.net...
> > Dave,
> >
> > Looks like you might have one too many backslashes in your $path...
> >
> > Dave wrote:
> >
> > > Hi,
> > > I have a simple program using Win32::ChangeNotify that
> > > works on my Win98 machine but does not work on the
> > > same
> > > machine when booted as a Win NT Server.
> > >
> > > The code dies on the Win32::ChangeNotify->new line.
> > > (No error message is displayed, is just says
> > > "monitorDir.pl die on line 14". So I guess $! must be blank?)
> > >
> > > If I change the $path to "C:" under Win NT, it runs,
> > > but acts "funny".  By "funny" I mean that it does not
> > > stop the monitoring when I place a file in "C:".
> > > Meanwhile, once again, on a Win98 machine, everything
> > > works.  Help!!!  What the heck is wrong?
> > >
> > >  use strict;
> > >  use Win32::ChangeNotify;
> > > # Look for any changes in the watched Dir.
> > > # Changes include renames, deletions and creations.
> > >  my $filter = "FILE_NAME";
> > >
> > >  my ($notify);
> > >  my $path =  "C:\\\\Timothymarsch\\SHARE";
> > >
> > >  my $subTree = 1;
> > >  my $retValue;  # return value
> > >
> > >  $notify = Win32::ChangeNotify->new($path, $subTree,
> > > $filter) || die $!;
> > >  $retValue = $notify -> wait or die "Something failed:
> > > $!\n";
> > >
> > >  if ($retValue == 1) {
> > >      print "hip, hip horaay!\n";
> > >  } else {
> > >  print STDERR "$notify\n";
> > >  }
> > >
> > > TIA,
> > > Dave
> >
> > --
> > Q: Why is Batman better than Bill Gates?
> > A: Batman was able to beat the Penguin.
> >
> >

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 172
**************************************


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