Re: a question on the symbol

2009-12-13 Thread Peter Scott
On Sun, 13 Dec 2009 23:43:44 +0800, Xiao Lan (小兰)
wrote:

> Hello,
> 
>   my $obj;
> 
>   my $h;
>   foreach $h (@{ref($hosts) ? $hosts : [$hosts]}) {
> $obj = $type->SUPER::new(
>   PeerAddr => ($host = $h),
>   PeerPort => $arg{Port} || 'smtp(25)', LocalAddr =>
>   $arg{LocalAddr},
>   LocalPort => $arg{LocalPort},
>   Proto => 'tcp',
>   Timeout   => defined $arg{Timeout}
>   ? $arg{Timeout}
>   : 120
>   )
>   and last;
>   }
> 
>   return undef
> unless defined $obj;
> 
>   $obj->autoflush(1);
> 
>   $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
> 
>   unless ($obj->response() == CMD_OK) {
> $obj->close();
> return undef;
>   }
> 
>   ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
>   ${*$obj}{'net_smtp_host'}   = $host;
> 
> 
> 
> What's the *$obj here?

This is by no stretch of the imagination a beginner's question.

Your extract of the Net::SMTP constructor shows that the module creates an 
object by creating a object in the parent class.  This turns out to be the 
constructor for IO::Handle, which returns a blessed reference to an 
anonymous glob formed with Symbol::gensym.

*Named* globs are hard enough to grok, let alone anonymous ones.

But that means that $obj can be dereferenced to the glob and thence 
variables can be populated in its package.  This is how object attributes 
are done in this suite.  The names are prefixed with net_smtp_ to avoid 
colliding with parent class attributes.

This is not a common object implementation model.  I do not suggest you 
emulate it.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




a question on the symbol

2009-12-13 Thread 小兰
Hello,

  my $obj;

  my $h;
  foreach $h (@{ref($hosts) ? $hosts : [$hosts]}) {
$obj = $type->SUPER::new(
  PeerAddr => ($host = $h),
  PeerPort => $arg{Port} || 'smtp(25)',
  LocalAddr => $arg{LocalAddr},
  LocalPort => $arg{LocalPort},
  Proto => 'tcp',
  Timeout   => defined $arg{Timeout}
  ? $arg{Timeout}
  : 120
  )
  and last;
  }

  return undef
unless defined $obj;

  $obj->autoflush(1);

  $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);

  unless ($obj->response() == CMD_OK) {
$obj->close();
return undef;
  }

  ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
  ${*$obj}{'net_smtp_host'}   = $host;



What's the *$obj here?
I think it could be *obj, but since $obj is declared with my, so *obj
is also invalid.

Thanks.

//Xiao lan

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Manipulating the symbol table

2009-06-28 Thread Dr.Ruud

Steve Bertrand wrote:


$user->{'username'} = 'steveb'; # in an app

I could then replace it instead with:

$user->username('steveb');


See also Class::Accessor::Faster
and http://search.cpan.org/~spurkis/accessors/

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Manipulating the symbol table

2009-06-27 Thread Steve Bertrand
I've been reading quite a bit of docs the last few days, and in
"perltooc", I came across some neat tricks. Admittedly though, although
I understood it well enough to get excited about some of the techniques,
a reasonable portion of the details flew above my head (at this time).

One issue I've been dealing with is updating my modules with accessors,
instead of my applications using the instance variables directly.

In the mentioned perldoc, there are snips of code showing how to update
the symbol table to reference a subroutine with the same name as each
key in an object's hashref. In my case, it'd look something like this:

for my $datum (keys %User) {
no strict "refs";

*$datum = sub {
shift; # drop the caller
$User{$datum} = shift if @_;
return $User{$datum};
}
}

If I understand correctly, if I've done the above, and currently  have this:

$user->{'username'} = 'steveb'; # in an app

I could then replace it instead with:

$user->username('steveb');

I'm not asking for a lack of trying. I'm just trying to ensure I
understand correctly so far, and if so, if I change my internal names, I
could then create 'alias' entries that point the old name to the new
instance variable.

Steve


smime.p7s
Description: S/MIME Cryptographic Signature


RE: The "@" symbol

2006-01-13 Thread Timothy Johnson

I just ran into this the other day.  It is easy to forget the different
ways that the << operator can be used.  Basically Perl looks at the way
you quote your termination string (HERE, EOF, etc.).  If you don't quote
it, Perl will assume double-quotes.  Put single quotes around your
termination string to avoid accidental interpolation in your
strings(E.g. <<'HERE' instead of <From perldoc perlop:

   print <mailto:[EMAIL PROTECTED] 
Sent: Friday, January 13, 2006 8:28 AM
To: beginners@perl.org
Subject: The "@" symbol

trying to include the following code with the abc.pl script...

the snippet works in an html/css environment

print <
@import url("theta.css"); 
@media print {
body {background: white; color: black; font: 12pt Times,
serif;}
#noprnt {display: none !important;}
}


EOF

The "@" symbols are misread and thus this cause errors...  escaping the
"@" symbols doesn't work



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: The "@" symbol

2006-01-13 Thread Chris Devers
On Fri, 13 Jan 2006, Gerald Wheeler wrote:

> trying to include the following code with the abc.pl script...
> 
> the snippet works in an html/css environment
> 
> print < 
>   
>   @import url("theta.css"); 
>   @media print {
>   body {background: white; color: black; font: 12pt Times,
> serif;}
>   #noprnt {display: none !important;}
>   }
>   
> 
> EOF
> 
> The "@" symbols are misread and thus this cause errors...  escaping the
> "@" symbols doesn't work
> 
> anyone with a solution??

This is part of why I hate heredocs. Just use a regular single- or 
double- quoted print statement with a custom quote delimiter:

print q[

@import url("theta.css");
@media print {
body {background: white; color: black; font: 12pt Times, serif;}
#noprnt {display: none !important;}
}

];

Less fiddly, easier to read, works as well or better.

Heredocs are for grizzled old shell-scripters that refuse to let go of 
their scars :-)



-- 
Chris Devers
DO NOT LEAVE IT IS NOT REAL

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: The "@" symbol

2006-01-13 Thread Tom Phoenix
On 1/13/06, Gerald Wheeler <[EMAIL PROTECTED]> wrote:

> The "@" symbols are misread and thus this cause errors...  escaping the
> "@" symbols doesn't work

It should work if you escape them correctly, which is to say with a
preceding backslash. How did you escape them that didn't work?

> print  




Re: The "@" symbol

2006-01-13 Thread Adriano Ferreira
On 1/13/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:
> It is in core documentation somewhere, even though I could not locate
> it right now.

Here it is: try C in the section "Regexp Quote-Like
Operators", search for the item  




Re: The "@" symbol

2006-01-13 Thread Adriano Ferreira
A here document (like the one you wrote in your script between
"< wrote:
> trying to include the following code with the abc.pl script...
>
> the snippet works in an html/css environment
>
> print <
> 
> @import url("theta.css");
> @media print {
> body {background: white; color: black; font: 12pt Times,
> serif;}
> #noprnt {display: none !important;}
> }
> 
>
> EOF
>
> The "@" symbols are misread and thus this cause errors...  escaping the
> "@" symbols doesn't work
>
> anyone with a solution??
>
> Thanks
>
> Jerry
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




The "@" symbol

2006-01-13 Thread Gerald Wheeler
trying to include the following code with the abc.pl script...

the snippet works in an html/css environment

print <
@import url("theta.css"); 
@media print {
body {background: white; color: black; font: 12pt Times,
serif;}
#noprnt {display: none !important;}
}


EOF

The "@" symbols are misread and thus this cause errors...  escaping the
"@" symbols doesn't work

anyone with a solution??

Thanks

Jerry

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: input with the < symbol

2002-04-12 Thread John W. Krahn

Mike wrote:
> 
> What happens if I call a perl script as follows:
> 
> test.pl < abc

The contents of the file "abc" are directed to the standard input of
"test.pl"


> What picks up the abc inside the script?  In shell scripting I would just
> use a read statement (read a).  Is there a like function in perl?

# reads from standard input, stores the current line in $_
while (  ) {

# use the <> special null file handle to read from standard input
while ( <> ) {


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




input with the < symbol

2002-04-12 Thread Mike

What happens if I call a perl script as follows:

test.pl < abc

What picks up the abc inside the script?  In shell scripting I would just
use a read statement (read a).  Is there a like function in perl?




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: The > symbol in a variable

2001-08-24 Thread Christopher Solomon




On Thu, 23 Aug 2001, Buffy Press wrote:

> Hello,
> 
> I am *very new* to Perl and to this list.  I have a question I am hoping
> someone can answer.  I am looking over an existing Perl script and came
> across this block of code:
> 
>  # Create the cmdfile
>   my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>   exit $? if system($runprog);
> 
> Can anyone tell me what the > symbol means here:
> 
> my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>
> I have looked in O'Reilly's Programming Perl book and found lots of
> information about the > symbol, but I could not see how it relates in
> the above variable.


Ok, here's what's happening.  That whole section in double-quotes is being
used as the parameter for the system() function, right?  Just so you know,
system() executes shell (command prompt) commands for you inside a perl
script, e.g. system("ls -al").

In shell-speak, the > operator is something of a redirect.  It has nothing
to do with Perl so to speak but has to do with the external command.  

Think of it as an arrow.
What is going to happen is that everything to the left of the 'arrow' will
be redirected to where the arrow is pointing.  In other words, the
"$NexBase::idx..." will be fed the the standard input of the
program/command "$cmdfile".  

One example of this could be:

ModuleFoo::Blah/bin/foobar > foomailer

This will (theoretically) mail someone the contents of the 'foobar' file
in the specified directory.

I hope this hasn't confused you even more.  

The short answer is that it's not a Perl thing, but rather, a shell thing.

;)

Chris 

> 
> Any help is appreciated.  
> 
> Thanks,
> Buffy
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: The > symbol in a variable

2001-08-24 Thread register

The system function runs a command in the OS shell.  Whatever is in the params
of system is never Perl code (well maybe it could be if you were using a perl
shell but that is another story) ... the '>' is a redirection operator to
redirect the output to a file or handle ..

hope this helps

On Thu, Aug 23, 2001 at 09:52:03AM -0700, Buffy Press shaped the electrons to read:
> Hello,
> 
> I am *very new* to Perl and to this list.  I have a question I am hoping
> someone can answer.  I am looking over an existing Perl script and came
> across this block of code:
> 
>  # Create the cmdfile
>   my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>   exit $? if system($runprog);
> 
> Can anyone tell me what the > symbol means here:
> 
> my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>
> I have looked in O'Reilly's Programming Perl book and found lots of
> information about the > symbol, but I could not see how it relates in
> the above variable.
> 
> Any help is appreciated.  
> 
> Thanks,
> Buffy
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




The > symbol in a variable

2001-08-24 Thread Buffy Press

Hello,

I am *very new* to Perl and to this list.  I have a question I am hoping
someone can answer.  I am looking over an existing Perl script and came
across this block of code:

 # Create the cmdfile
  my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
  exit $? if system($runprog);

Can anyone tell me what the > symbol means here:

my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
   
I have looked in O'Reilly's Programming Perl book and found lots of
information about the > symbol, but I could not see how it relates in
the above variable.

Any help is appreciated.  

Thanks,
Buffy

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: The > symbol in a variable

2001-08-23 Thread Peter Scott

At 11:20 AM 8/23/01 -0700, Buffy Press wrote:
>Hello,
>
>I am *very new* to Perl and to this list.  I have a question I am hoping
>someone can answer.  I am looking over an existing Perl script and came
>across this block of code:
>
>  # Create the cmdfile
>   my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>   exit $? if system($runprog);
>
>Can anyone tell me what the > symbol means here:
>
>my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
>
>I have looked in O'Reilly's Programming Perl book and found lots of
>information about the > symbol, but I could not see how it relates in
>the above variable.

That symbol is not going to be used by Perl.  The variable $runprog is 
being initialized to contain a command to be passed to your OS' command 
line interpreter (the Bourne shell on Unix-y systems).  You'll see $runprog 
used later in that program in either a system() or exec() function call, or 
between backticks (``) (or, less likely, in an open() call).

If you're unfamiliar with the Bourne shell, consult a reference such as 
"Unix Shell Programming" by Kochan & Wood, Hayden Books (happens to be on 
the shelf in front of me).

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




The > symbol in a variable

2001-08-23 Thread Buffy Press

Hello,

I am *very new* to Perl and to this list.  I have a question I am hoping
someone can answer.  I am looking over an existing Perl script and came
across this block of code:

 # Create the cmdfile
  my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
  exit $? if system($runprog);

Can anyone tell me what the > symbol means here:

my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile";
   
I have looked in O'Reilly's Programming Perl book and found lots of
information about the > symbol, but I could not see how it relates in
the above variable.

Any help is appreciated.  

Thanks,
Buffy

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: checking for the @ symbol

2001-06-12 Thread Aaron Craig

At 11:50 12.06.2001 -0400, Chas Owens wrote:

>\w includes _.  The \w character set is anything that can be included
>in a variable name.  On the topic of shortening the regexp: "." in a
>character class does not need to be escaped so you can write it like
>this
>
>  print "You're cheating!" if($add_alias =~ /[^\w.\-]/);


thanks for pointing that out!
Aaron Craig
Programming
iSoftitler.com




Re: checking for the @ symbol

2001-06-12 Thread Hasanuddin Tamir

On Tue, 12 Jun 2001, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote,

> > print "You're cheating!" if($add_alias =~ /[^\w\.\-]/g);  # \w Match a
> > "word" character (alphanumeric plus "_")
> >
>
>   wow. thanks. that looks just like what i need. however, i also
>   want to match the _ character as well. so will
>
>   /[^\w\.\-\_]/
>
>   work for me?

Yes, it will.  Just to note again that the "_" (underscore) is already
included in \w.  Repeat, 'alphanumeric plus "_"'.  Also, if you put the
"-" (dash) in the last sequence (just before the the closing "]"), you
don't need to escape it.  You don't need the escape either for the ".",
it means literal inside character class.

So this one will work equally,

/[^\w.-]/


s::a::n
-- 
http://www.trabas.com




Re: checking for the @ symbol

2001-06-12 Thread Chas Owens

On 12 Jun 2001 10:24:23 -0500, [EMAIL PROTECTED] wrote:
> > print "You're cheating!" if($add_alias =~ /[^\w\.\-]/g);  # \w Match a
> > "word" character (alphanumeric plus "_")
> >
> 
>   wow. thanks. that looks just like what i need. however, i also
>   want to match the _ character as well. so will
> 
>   /[^\w\.\-\_]/
> 
>   work for me?
> 
>   thanks!

\w includes _.  The \w character set is anything that can be included 
in a variable name.  On the topic of shortening the regexp: "." in a 
character class does not need to be escaped so you can write it like 
this

 print "You're cheating!" if($add_alias =~ /[^\w.\-]/);

--
Today is Pungenday, the 17th day of Confusion in the YOLD 3167
Umlaut Zebra über alles!





Re: checking for the @ symbol

2001-06-12 Thread charles

> print "You're cheating!" if($add_alias =~ /[^\w\.\-]/g);  # \w Match a
> "word" character (alphanumeric plus "_")
>

wow. thanks. that looks just like what i need. however, i also
want to match the _ character as well. so will

/[^\w\.\-\_]/

work for me?

thanks!




Re: checking for the @ symbol

2001-06-12 Thread Aaron Craig

At 09:29 12.06.2001 -0500, you wrote:

>i am printing to the file currently via:
>
>   open(FILE, ">>$filename");
> print FILE "$add_alias\@$domain\t$add_destination\n";
>   close(FILE);
>
>so i am appending the appropriate domain to the new alias they are
>entering. overall, i want to ensure that $add_alias is composed
>strictly of a-z,A-Z,0-9,.,- and _ and nothing else.

then it doesn't sound like you're worried about finding a '@', it sounds 
like you're worried about finding anything that is not A-Za-z0-9\.\-_ which 
fits nicely into the following regular expression

print "You're cheating!" if($add_alias =~ /[^A-Za-z0-9\.\-_]/g);

or even more concise

print "You're cheating!" if($add_alias =~ /[^\w\.\-]/g);  # \w Match a 
"word" character (alphanumeric plus "_")



Aaron Craig
Programming
iSoftitler.com




Re: checking for the @ symbol

2001-06-12 Thread charles


Sure, no problem.

i am writing a "control panel" of sorts for individuals to use to
administrate their virtual emails on a linux based sendmail server.
each client has a file in /etc/mail/include that holds tab delimited
entries for their email aliases:

[EMAIL PROTECTED]   [EMAIL PROTECTED]

the front end form that allows them to enter new alias/pair destination is
directed via 'post' to my perl script. i want to ensure that in their
'alias' entry, they cannot include an @symbol in the malicious attempt to
direct traffic of another client to a bogus address.

i am printing to the file currently via:

  open(FILE, ">>$filename");
print FILE "$add_alias\@$domain\t$add_destination\n";
  close(FILE);

so i am appending the appropriate domain to the new alias they are
entering. overall, i want to ensure that $add_alias is composed
strictly of a-z,A-Z,0-9,.,- and _ and nothing else.


On Mon, 11 Jun 2001, Peter Scott wrote:

> At 11:08 PM 6/11/01 -0500, [EMAIL PROTECTED] wrote:
>
> >i am writing a script that tests to see if an \@ symbol is entered by an
> >end user. i am trying to look at other alternatives that a malicious end
> >user might do to get around my checking. right now, i am doing a simple
> >
> > if ( $add_alias =~ /\@/ ) {
> >
> >could an end user enter an escaped ascii character code that would be
> >interpretted as \@
>
> Interpreted in what context?  I'm not aware of how a lowly @ character in
> your input could pose a danger, so if you enlightened us as to exactly what
> you're concerned about perhaps we can help.
> --
> Peter Scott
> Pacific Systems Design Technologies
> http://www.perldebugged.com
>




Re: checking for the @ symbol

2001-06-11 Thread Peter Scott

At 11:08 PM 6/11/01 -0500, [EMAIL PROTECTED] wrote:

>i am writing a script that tests to see if an \@ symbol is entered by an
>end user. i am trying to look at other alternatives that a malicious end
>user might do to get around my checking. right now, i am doing a simple
>
> if ( $add_alias =~ /\@/ ) {
>
>could an end user enter an escaped ascii character code that would be
>interpretted as \@

Interpreted in what context?  I'm not aware of how a lowly @ character in 
your input could pose a danger, so if you enlightened us as to exactly what 
you're concerned about perhaps we can help.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




checking for the @ symbol

2001-06-11 Thread charles

i am writing a script that tests to see if an \@ symbol is entered by an
end user. i am trying to look at other alternatives that a malicious end
user might do to get around my checking. right now, i am doing a simple

if ( $add_alias =~ /\@/ ) {

could an end user enter an escaped ascii character code that would be
interpretted as \@

thanks -cjm