[29331] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 575 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 25 16:14:20 2007

Date: Mon, 25 Jun 2007 13:14:13 -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           Mon, 25 Jun 2007     Volume: 11 Number: 575

Today's topics:
        strings with formatted characters in %ARGV  mfrost8@gmail.com
    Re: strings with formatted characters in %ARGV anno4000@radom.zrz.tu-berlin.de
    Re: strings with formatted characters in %ARGV <jurgenex@hotmail.com>
    Re: strings with formatted characters in %ARGV  mfrost8@gmail.com
    Re: strings with formatted characters in %ARGV  mfrost8@gmail.com
    Re: The Modernization of Emacs: terminology buffer and  <andreas_eder@gmx.net>
    Re: uninitialized value <saleem.a.ansari@gmail.com>
        User Management and Authentication with Perl <ilias@lazaridis.com>
    Re: User Management and Authentication with Perl <ts@dionic.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 25 Jun 2007 09:33:13 -0700
From:  mfrost8@gmail.com
Subject: strings with formatted characters in %ARGV
Message-Id: <1182789193.720524.171250@x35g2000prf.googlegroups.com>

I thought I knew  perl pretty well, but then this came up and has me
totally stumped -- making me realize I don't understand it as well as
I thought...

I'm trying to pass one or more formatted (i.e. with '\n' in it)
strings to a perl program and have them print with the formatting.
Consider the following perl code:

    #!/usr/bin/perl
    print $ARGV[0];

Now if I run the program as follows:

    $ ./x.pl "FOO\n\n\n"

I get

    FOO\n\n\n$

which I don't understand.  If I set a scalar string within the program
similarly:

    #!/usr/bin/perl
    my $foo = "FOO\n\n\n";
    print $foo;

I get what I'd expect.

What am I missing here?  Why can't I get print/printf to honor those
special characters when used from the command line?

Thanks



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

Date: 25 Jun 2007 16:43:17 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: strings with formatted characters in %ARGV
Message-Id: <5ea9l5F374d19U1@mid.dfncis.de>

 <mfrost8@gmail.com> wrote in comp.lang.perl.misc:
> I thought I knew  perl pretty well, but then this came up and has me
> totally stumped -- making me realize I don't understand it as well as
> I thought...
> 
> I'm trying to pass one or more formatted (i.e. with '\n' in it)
> strings to a perl program and have them print with the formatting.
> Consider the following perl code:
> 
>     #!/usr/bin/perl
>     print $ARGV[0];
> 
> Now if I run the program as follows:
> 
>     $ ./x.pl "FOO\n\n\n"
> 
> I get
> 
>     FOO\n\n\n$

This is discussed in the FAQ "How can I expand variables in text strings?".
While you want to expand escape sequences and not variables, the reason
for the behavior and the solutions are similar.

Anno


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

Date: Mon, 25 Jun 2007 16:50:56 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: strings with formatted characters in %ARGV
Message-Id: <QnSfi.12412$XH5.6178@trndny02>

mfrost8@gmail.com wrote:
> I'm trying to pass one or more formatted (i.e. with '\n' in it)
> strings to a perl program and have them print with the formatting.

'\n' has nothing to do with formatting. It is a representation of a 
character, that otherwise could not by typed.

> Now if I run the program as follows:
>    $ ./x.pl "FOO\n\n\n"
>
> I get
>    FOO\n\n\n$
>
> which I don't understand.  If I set a scalar string within the program
> similarly:
>    my $foo = "FOO\n\n\n";
>    print $foo;
>
> I get what I'd expect.
>
> What am I missing here?  Why can't I get print/printf to honor those
> special characters when used from the command line?

You are confusing program text and data.
    my $foo = "FOO\n\n\n";
is program source code. When interpreted the Perl interpreter will convert 
this into the text FOO followed by three newlines in whatever representation 
is needed for your OS AND THEN STORE THIS DATA ITEM. This happens as compile 
time.

However when reading parameters from the command line Perl reads that data 
as is because it is data already, no need to interpret it.

By a similar argument you could ask why
    ./x.pl "print 'Hello world'"
doesn't print the text Hello World.

jue




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

Date: Mon, 25 Jun 2007 11:51:06 -0700
From:  mfrost8@gmail.com
Subject: Re: strings with formatted characters in %ARGV
Message-Id: <1182797466.726134.13010@n60g2000hse.googlegroups.com>

On Jun 25, 12:50 pm, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
> mfro...@gmail.com wrote:
> > I'm trying to pass one or more formatted (i.e. with '\n' in it)
> > strings to a perl program and have them print with the formatting.
>
> '\n' has nothing to do with formatting. It is a representation of a
> character, that otherwise could not by typed.
>
> > Now if I run the program as follows:
> >    $ ./x.pl "FOO\n\n\n"
>
> > I get
> >    FOO\n\n\n$
>
> > which I don't understand.  If I set a scalar string within the program
> > similarly:
> >    my $foo =3D "FOO\n\n\n";
> >    print $foo;
>
> > I get what I'd expect.
>
> > What am I missing here?  Why can't I get print/printf to honor those
> > special characters when used from the command line?
>
> You are confusing program text and data.
>     my $foo =3D "FOO\n\n\n";
> is program source code. When interpreted the Perl interpreter will convert
> this into the text FOO followed by three newlines in whatever representat=
ion
> is needed for your OS AND THEN STORE THIS DATA ITEM. This happens as comp=
ile
> time.
>
> However when reading parameters from the command line Perl reads that data
> as is because it is data already, no need to interpret it.
>
> By a similar argument you could ask why
>     ./x.pl "print 'Hello world'"
> doesn't print the text Hello World.
>
> jue

Huh.  Interesting.  I guess I got burned here by how perl usually
understands what you want to do without having to explicitly specify
it.

I could see this in the case of variables in a string -- how would
perl know what "$foo" is?  But I would have thought that
representations of special characters like '\n' would be treated
differently.

My assumption here would be that when running using a function like
print that kind of assumes it's working with strings that it would
interpret that 2-character sequence when it was invoked.

So then this means that I have to parse out all the 2-character
sequences myself and replace them?  I read the FAQ entry that the
previous poster sent and it seemed to use a regex to do substitutions
on the string which then replaced the same string with itself.  I
didn't have much success bending that FAQ to do my bidding.  I tried a
few things, but the last thing I tried was simply

my $foo =3D $ARGV[0];
$foo =3D~ s/(\\n)/$1/g;
print $foo;

Which didn't seem to change anything.

What do I need to do to make this work the way I expect it to?

Thanks very much for your time and input.



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

Date: Mon, 25 Jun 2007 11:55:12 -0700
From:  mfrost8@gmail.com
Subject: Re: strings with formatted characters in %ARGV
Message-Id: <1182797712.451983.3740@w5g2000hsg.googlegroups.com>

On Jun 25, 2:51 pm, mfro...@gmail.com wrote:
> On Jun 25, 12:50 pm, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:
>  I tried a
> few things, but the last thing I tried was simply
>
> my $foo =3D $ARGV[0];
> $foo =3D~ s/(\\n)/$1/g;
> print $foo;
>
> Which didn't seem to change anything.
>
> What do I need to do to make this work the way I expect it to?
>
> Thanks very much for your time and input.

Whoops.  I meant to say that I'd tried

my $foo =3D $ARGV[0];
eval { $foo =3D~ s/(\\n)/$1/eeg };
print $foo;

and that didn't yield anything different.

Thanks



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

Date: Mon, 25 Jun 2007 19:23:06 +0200
From: Andreas Eder <andreas_eder@gmx.net>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <86abuoaqyt.fsf@eder.homelinux.net>

Hi Twisted,

>>>>> "Twisted" == Twisted  <twisted0n3@gmail.com> writes:

    Twisted> That's entirely orthogonal to the issue of interface learning curve OR
    Twisted> interface ease-of-use. Emacs has deficiencies in both areas, if
    Twisted> principally the former. (For an example of the latter, consider
    Twisted> opening a file. Can't remember the exact spelling and capitalization
    Twisted> of the file name? Sorry, bud, you're SOL.

Wrong, ever heard about input completion?

    Twisted> Go find it in some other app
    Twisted> and memorize the name, then return to emacs.

Wrong. Do you know dired?

For even more ease of use use someting like ido, or icicles. It
runs rings about Editors like Notepad.

    Twisted> Now THAT is what I call
    Twisted> disruptive context switching. Meanwhile even the lowly Notepad
    Twisted> responds to "open" by displaying a list of text files and tools to
    Twisted> navigate the folder hierarchy without having to do it blind, while
    Twisted> still letting you blind-type a path if you remember it. And you can
    Twisted> also paste the path in from the clipboard.

You can do so in emacs as well.

    Twisted> Unix systems don't even
    Twisted> *have* a proper system-wide clipboard and copy/paste capability. Under
    Twisted> X there's a weak, text-only imitation, which doesn't help you much
    Twisted> when you want to copy a selection from an image in a paint program and
    Twisted> paste it into a CAD or web-design or specialized image-manipulation
    Twisted> tool or whatever...you have to save it to a file and load it, which is
    Twisted> a pain in the butt and slowly clutters your hard drive with
    Twisted> "temporary" files you occasionally forget to delete.

You obviously have no clue about working under Unix either.

'Andreas

-- 
Wherever I lay my .emacs, there's my $HOME.


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

Date: Mon, 25 Jun 2007 13:28:52 -0000
From:  tuxdna <saleem.a.ansari@gmail.com>
Subject: Re: uninitialized value
Message-Id: <1182778132.592121.189530@j4g2000prf.googlegroups.com>

On Jun 24, 1:06 am, jan09...@hotmail.com wrote:
> Hi,
> I try to learn perl by myself without any programming background. I
> try to transform my DATA to
> #title -fruit-#
> orange => orange, carot,
> red => apple, cherry, strawberry
> #title -vegetables-#
> green => cucumber
> red => tomatoes
>
> I keep on receiving this message  Use of uninitialized value in join
> or string at ./print.pl line 18, <DATA> line 8. and don't know what to
> do to fix the problem.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $title = "#.*#";
> my %hash;
>
>  while(<DATA>) {
>   chomp;
>  {
>     my($key,$val) = split(/\s*=>\s*/);
>     push(@{$hash{$key}},$val);
>   }
>
> for my $key (sort keys %hash) {
>  print "$key => @{$hash{$key}}\n";
> print $titles;
>
> }
> }
>
> __DATA__
> #title -fruit-#
> orange => orange
> orange => carot
> red => apple
> red => cherry
> red => strawberry
> #title -vegetables-#
> green => cucumber
> red => tomatoes


Check this one. This Works.

#!/usr/bin/
perl
use
warnings;
use
strict;

my %hash=();

while(<DATA>)
{
  if ( /^
\#/ )
  {
    for my $key (sort keys
%hash)
 
{
      print "$key => ", join(", " ,
@{$hash{$key}}),"\n";
    }
    print
$_;
 
%hash=();
 
next;
  }
 
chomp;

  my($key,$val) = split(/\s*=>
\s*/);
  push( @{$hash{$key}} ,
$val );
}

for my $key (sort keys
%hash)
{
  print "$key => ", join(", " ,
@{$hash{$key}}),"\n";
}

__DATA__
#title -fruit-
#
orange =>
orange
orange => carot
red =>
apple
red =>
cherry
red =>
strawberry
#title -vegetables-
#
green =>
cucumber
red => tomatoes



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

Date: Mon, 25 Jun 2007 06:11:58 -0700
From:  Ilias Lazaridis <ilias@lazaridis.com>
Subject: User Management and Authentication with Perl
Message-Id: <1182777118.212000.77230@u2g2000hsc.googlegroups.com>

Is there any user-management/authentication solution which could be
seen as the standard within the perl domain?

Is there any solution available which makes a general interface
available and allows "authenticators" to be plugged-in (e.g. an
"Standard Unix", an "Open Id" plugin)?

Are those solutions scalable (e.g. runs first on one machine, then can
be moved to a dedicated authentication machine)?

Is there any worked-out overview available?

 .

--
http://dev.lazaridis.com/lang/ticket/18



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

Date: Mon, 25 Jun 2007 14:26:22 +0100
From: Tim Southerwood <ts@dionic.net>
Subject: Re: User Management and Authentication with Perl
Message-Id: <467fc27e$0$647$5a6aecb4@news.aaisp.net.uk>

Ilias Lazaridis wrote:

> Is there any user-management/authentication solution which could be
> seen as the standard within the perl domain?

Hi

For authorisation/authentication, PAM is pretty much the defacto standard on
linux at least.

See here for a list of perl modules:

http://search.cpan.org/search?query=pam&mode=all

PAM is a standard client API to a variety of account and authentication
mechanisms, including, but not limited to:

local files (passwd/group/shadow)
NIS/NIS+
LDAP
Kerberos

> 
> Is there any solution available which makes a general interface
> available and allows "authenticators" to be plugged-in (e.g. an
> "Standard Unix", an "Open Id" plugin)?
> 
> Are those solutions scalable (e.g. runs first on one machine, then can
> be moved to a dedicated authentication machine)?

PAM is a client side solution. Are you asking if there is an auth/account
server framework for perl? I don't think so - and I think you are better
off using perl to manage in an automated way (if required) something
existing that's proven good like kerberos plus LDAP/NIS/local-files.

HTH
Tim


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

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 V11 Issue 575
**************************************


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