[30590] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1833 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 2 21:09:45 2008

Date: Tue, 2 Sep 2008 18:09:11 -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           Tue, 2 Sep 2008     Volume: 11 Number: 1833

Today's topics:
    Re: [Q] How to seach an unmapped network drive <damercer@comcast.net>
    Re: FAQ 6.18 Why don't word-boundary searches with "\b" <jurgenex@hotmail.com>
    Re: FAQ 6.18 Why don't word-boundary searches with "\b" <someone@example.com>
    Re: FAQ 6.18 Why don't word-boundary searches with "\b" <RedGrittyBrick@spamweary.invalid>
        help message with no input options <slick.users@gmail.com>
    Re: help message with no input options <smallpond@juno.com>
    Re: help message with no input options <slick.users@gmail.com>
    Re: help message with no input options <smallpond@juno.com>
    Re: help message with no input options <cartercc@gmail.com>
    Re: help message with no input options <slick.users@gmail.com>
    Re: Integrating Inline-C-based module into a Perl distr <sisyphus359@gmail.com>
    Re: Integrating Inline-C-based module into a Perl distr <sisyphus359@gmail.com>
    Re: is there a GUI for Perl to display large tree struc <glennj@ncf.ca>
        perl - CGI problem <zhilianghu@gmail.com>
    Re: perl - CGI problem <1usa@llenroc.ude.invalid>
    Re: perl - CGI problem xhoster@gmail.com
    Re: Prolem examining JavaScript with SpiderMonkey.pm <joost@zeekat.nl>
    Re: Prolem examining JavaScript with SpiderMonkey.pm <john@castleamber.com>
        using 2-arg open to open to a scalar xhoster@gmail.com
    Re: using 2-arg open to open to a scalar <someone@example.com>
    Re: using 2-arg open to open to a scalar <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 2 Sep 2008 17:56:18 -0500
From: "Dan Mercer" <damercer@comcast.net>
Subject: Re: [Q] How to seach an unmapped network drive
Message-Id: <oomdnTqLSIUTWSDVnZ2dnUVZ_s_inZ2d@comcast.com>

"Back9" <LeeHwasoo@gmail.com> wrote in message 
news:ed231f68-3e76-4b25-956d-5f8cf897a04b@25g2000hsx.googlegroups.com...
> Hi,
>
> Does anyone know of how to seach an unmapped network drive in Windows
> XP to map it?
>
> Thanks,
> Hwasoo

Use the Uniform Naming Convention (\\servername\rootdir\subdirs)

Dan Mercer



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

Date: Tue, 02 Sep 2008 16:36:45 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 6.18 Why don't word-boundary searches with "\b" work for me?
Message-Id: <slqqb459kq932875nsinrhtd7bner34n09@4ax.com>

RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
>However I do have one suggestion for FAQ 6.18: The current version has 
>these two assertions:
>
>   "These patterns match /\Bam\B/:"
>   "These strings do not match /\Bam\B/"
>
>I suggest, for consistency, the word "patterns" in the first assertion 
>be replaced by "strings" (as in the second fragment).

And in addition it is the other way round (the pattern is the subject
and the string the object):

	"/\Bam\B/ matches these strings:"
	"/\Bam\B/ does not match these strings:"

or 

	"These strings are being match by /\Bam\B/:"
	"These strings are not being match by /\Bam\B/"

jue


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

Date: Tue, 02 Sep 2008 13:36:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: FAQ 6.18 Why don't word-boundary searches with "\b" work for me?
Message-Id: <9jbvk.62840$hx.42327@pd7urf3no>

RedGrittyBrick wrote:
> 
> PerlFAQ Server wrote:
> 
>>     You can also use the complement of \b, \B, to specify that there 
>> should
>>     not be a word boundary.
>>
>>     In the pattern /\Bam\B/, there must be a word character before the 
>> "a"
>>     and after the "m". These patterns match /\Bam\B/:
>>
>>             "llama"   # "am" surrounded by word chars
>>             "Samuel"  # same
>>
>>     These strings do not match /\Bam\B/
>>
>>             "Sam"      # no word boundary before "a", but one after "m"
>>             "I am Sam" # "am" surrounded by non-word chars
> 
> If /\Bam\B/ differs from /\wam\w/ maybe an example could be added to 
> illustrate this. If not, perhaps there is a better example of the use of 
> \B?

/\Bam\B/ matches two characters while /\wam\w/ matches four characters.

$ perl -le'$_ = "Samuel"; s/\Bam\B/ex/; print'
Sexuel
$ perl -le'$_ = "Samuel"; s/\wam\w/ex/; print'
exel


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 02 Sep 2008 16:46:12 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: FAQ 6.18 Why don't word-boundary searches with "\b" work for me?
Message-Id: <48bd5fc8$0$2927$fa0fcedb@news.zen.co.uk>


John W. Krahn wrote:
> RedGrittyBrick wrote:
>>
>> PerlFAQ Server wrote:
>>
>>>     You can also use the complement of \b, \B, to specify that there 
>>> should
>>>     not be a word boundary.
>>>
>>>     In the pattern /\Bam\B/, there must be a word character before 
>>> the "a"
>>>     and after the "m". These patterns match /\Bam\B/:
>>>
>>>             "llama"   # "am" surrounded by word chars
>>>             "Samuel"  # same
>>>
>>>     These strings do not match /\Bam\B/
>>>
>>>             "Sam"      # no word boundary before "a", but one after "m"
>>>             "I am Sam" # "am" surrounded by non-word chars
>>
>> If /\Bam\B/ differs from /\wam\w/ maybe an example could be added to 
>> illustrate this. If not, perhaps there is a better example of the use 
>> of \B?
> 
> /\Bam\B/ matches two characters while /\wam\w/ matches four characters.
> 
> $ perl -le'$_ = "Samuel"; s/\Bam\B/ex/; print'
> Sexuel
> $ perl -le'$_ = "Samuel"; s/\wam\w/ex/; print'
> exel
> 

Yes. I now realise my earlier suggestion is not relevant to this 
particular FAQ. I guess some other FAQ or perldoc clarifies when one 
might want to use \B and when \w.


However I do have one suggestion for FAQ 6.18: The current version has 
these two assertions:

   "These patterns match /\Bam\B/:"
   "These strings do not match /\Bam\B/"

I suggest, for consistency, the word "patterns" in the first assertion 
be replaced by "strings" (as in the second fragment).


-- 
RGB


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

Date: Tue, 2 Sep 2008 10:25:24 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: help message with no input options
Message-Id: <e069b9b2-c977-48ed-84fb-302a96cce8e3@k36g2000pri.googlegroups.com>

I am trying to print out the help message if no user input option is
used:

test2.pl runme #Print help usage

test2.pl runme -app "C:/a.exe" #Run script

I have try using scalar @ARGV == 0 but it doesn't help either.
Any idea? Thanks.


use strict;
use warnings;
use Getopt::Long;

main();
exit(0);

sub main
{
	my $subcmds =
	{
		"runme" =>
		{
			'sub'	=> \&subcmd_runme
		}
	};
	my $cmd = shift @ARGV;
	defined $cmd or $cmd = '';
	$subcmds->{$cmd} or die " No such command!\n";
	$subcmds->{$cmd}{'sub'}->(@ARGV);
}

sub subcmd_runme
{
	GetOptions
	(
		'app|a=s' 			=>	\my $opt_app,
		'file|f:s' 			=> 	\my $opt_file,
		'help|h' 			=> 	\my $opt_help
	);

	#print help if no user input options?
	print "Execute script \n";
}


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

Date: Tue, 2 Sep 2008 11:58:21 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: help message with no input options
Message-Id: <f49ff632-97bd-49c7-ba31-4ef4ca6f3558@73g2000hsx.googlegroups.com>

On Sep 2, 1:25 pm, Slickuser <slick.us...@gmail.com> wrote:
> I am trying to print out the help message if no user input option is
> used:
>


perl -e 'warn "No args" unless defined($ARGV[0])'
No args at -e line 1.

--S


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

Date: Tue, 2 Sep 2008 13:23:12 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: help message with no input options
Message-Id: <bd009f10-882a-41e2-8aea-267b15bc8a76@z6g2000pre.googlegroups.com>


Replace the sub routine and I still get error if I used input
arguments options.

> test2.pl runme
No args at line 33
Execute script

> test2.pl runme -app "C:/a.exe"
No args at line 33
Execute script


sub subcmd_runme
{
	GetOptions
	(
		'app|a=3Ds' 			=3D>	\my $opt_app,
		'file|f:s' 			=3D> 	\my $opt_file,
		'help|h' 			=3D> 	\my $opt_help
	);

	#print help if no user input options?
	warn "No args" unless defined($ARGV[0]);  ### line 33

	print "Execute script \n";
}

On Sep 2, 11:58=A0am, smallpond <smallp...@juno.com> wrote:
> On Sep 2, 1:25 pm, Slickuser <slick.us...@gmail.com> wrote:
>
> > I am trying to print out the help message if no user input option is
> > used:
>
> perl -e 'warn "No args" unless defined($ARGV[0])'
> No args at -e line 1.
>
> --S



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

Date: Tue, 2 Sep 2008 13:35:51 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: help message with no input options
Message-Id: <9fa96d90-9751-4f1b-a40b-e82bcfa8bf07@l42g2000hsc.googlegroups.com>

On Sep 2, 4:23 pm, Slickuser <slick.us...@gmail.com> wrote:
> Replace the sub routine and I still get error if I used input
> arguments options.
>


Many community colleges offer inexpensive introductory programming
classes.

--S


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

Date: Tue, 2 Sep 2008 14:06:28 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: help message with no input options
Message-Id: <c4609a0a-9de7-409e-bda6-ca5ffa954d27@k13g2000hse.googlegroups.com>

On Sep 2, 1:25=A0pm, Slickuser <slick.us...@gmail.com> wrote:
> I am trying to print out the help message if no user input option is
> used:

Check the command line arguments by looking at @ARGV. If the length of
@ARGV doesn't match what you want, print a usage message, like this:

$length =3D @ARGV;
if ($length !=3D $whatever_you_expect) {
 print "usage: whatever you expect\n";
}
else {
 call_main();
}
exit;

CC
CC


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

Date: Tue, 2 Sep 2008 14:15:44 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: help message with no input options
Message-Id: <4f88df9e-7de2-4ac8-bab2-e31d4d68ddd7@r35g2000prm.googlegroups.com>


test2.pl runme
Please enter subcommand user input options.

It shouldn't give me this message when I have options, but it does.

test2.pl runme -app a
Please enter subcommand user input options.

@ARGV is always zero.

sub subcmd_runme
{
	GetOptions
	(
		'app|a=3Ds' 			=3D>	\my $opt_app,
		'file|f:s' 			=3D> 	\my $opt_file,
		'help|h' 			=3D> 	\my $opt_help
	);

	#print help if no user input options?
	my $length =3D @ARGV;
	#my $length2 =3D scalar(@ARGV);
	#print "$length $length2 \n";
	if ($length =3D=3D 0) {
		die "Please enter subcommand user input options.\n";
	}

	print "Execute script \n";
}

On Sep 2, 2:06=A0pm, cartercc <carte...@gmail.com> wrote:
> On Sep 2, 1:25=A0pm, Slickuser <slick.us...@gmail.com> wrote:
>
> > I am trying to print out the help message if no user input option is
> > used:
>
> Check the command line arguments by looking at @ARGV. If the length of
> @ARGV doesn't match what you want, print a usage message, like this:
>
> $length =3D @ARGV;
> if ($length !=3D $whatever_you_expect) {
> =A0print "usage: whatever you expect\n";}
>
> else {
> =A0call_main();}
>
> exit;
>
> CC
> CC



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

Date: Tue, 2 Sep 2008 16:43:07 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: Integrating Inline-C-based module into a Perl distribution
Message-Id: <a24b0dc6-ae42-4c88-a8e6-31c2bd7317e4@p31g2000prf.googlegroups.com>

On Sep 2, 1:49=A0am, Thomas <t...@example.invalid> wrote:
 .
 .
> However, I still set libraries I depend on as absolute paths in the LIBS
> setting of my use Inline statement (..., 'LIBS =3D> c:/foo/bar.lib', ...)=
 .
> Unfortunately, I can't keep doing that.

Actually, you *can* keep doing that. That config info is used only
during compilation of the C code. Since the user doesn't have a
compiler, and since you're distributing pre-compiled binaries, there
will be no compilation done on the users machine. The LIBS setting
won't even be looked at ... you can ignore this aspect completely.

> I can't influence where the perl
> directory tree will be installed (could be c:\perl, d:\perl). What am I
> supposed to use as LIBS value? Where should the .lib files (or .so under
> Unix) go?

Those .lib files don't need to distributed at all. If they are import
libs for dlls, then the user needs only those dll's (as well as the
dll's that inline built). If those .lib files are static libraries,
then their functionality will have already been incorporated into the
dll's that inline built. Either way, there's no need to distribute
those .lib files.

>
> What's the standard way of distributing a module like mine? I have seen
> the Math::Simple example inhttp://search.cpan.org/~ingy/Inline-0.44/Inlin=
e.pod#Writing_Modules_w...

I think that's the best way to go in your case. Another alternative is
to rewrite your module as a "normal" cpan-type distribution - that has
no dependency upon Inline::C. (InlineX::C2XS can help with that - it
will write your XS file for you, even a Makefile.PL and .pm file if
you want.) Then you can build your module in the usual way and
distribute the package as a "normal" ppm.

> Everything works fine with
> absolute paths, but the exact configuration is my (last) obstacle. BTW,
> I also depend on the files Inline built to remain unchanged -- the
> user's system does not have a compiler or make to do the compilation.

Also, with this approach, the user's system will need to have the
Inline module installed. And if the user changes the C code in any
way, then Inline is going to want to re-compile ... which it can't do.
Better to go with the method outlined in the Inline-FAQ you referenced
above. I'm assuming that method removes the Inline dependency, as is
implied in that Inline-FAQ ... I *think* it does.

Cheers,
Rob


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

Date: Tue, 2 Sep 2008 16:48:45 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: Integrating Inline-C-based module into a Perl distribution
Message-Id: <40dcc4d7-1cb0-4953-be84-79bc9adb990a@q26g2000prq.googlegroups.com>

On Sep 3, 9:43=A0am, sisyphus <sisyphus...@gmail.com> wrote:
> On Sep 2, 1:49=A0am, Thomas <t...@example.invalid> wrote:
 .
 .
> > What's the standard way of distributing a module like mine? I have seen
> > the Math::Simple example inhttp://search.cpan.org/~ingy/Inline-0.44/Inl=
ine.pod#Writing_Modules_w...
>
> I think that's the best way to go in your case.

Ooh ... sorry, wrong link (I should have checked :-)
I thought that link you posted was a link to the Inline-FAQ. It's not.
The Inline-FAQ is here:
http://search.cpan.org/~ingy/Inline-0.44/Inline-FAQ.pod
Look for the section "How do I create a binary distribution using
Inline?".

That's the documentation you need to read.

Cheers,
Rob


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

Date: 2 Sep 2008 13:09:35 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: is there a GUI for Perl to display large tree structures ?
Message-Id: <slrngbqeog.651.glennj@smeagol.ncf.ca>

At 2008-08-31 07:48PM, "xhoster@gmail.com" wrote:
[...]
>  the data to XML and then try using various XML viewing tools to see of one
>  does what you want.  I'll the ones I've seen did branch collapsing, but
>  I don't know of any do searching by regex, but I've never looked.

Where's robic0 when you need him?

-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


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

Date: Tue, 2 Sep 2008 12:09:02 -0700 (PDT)
From: Zhiliang Hu <zhilianghu@gmail.com>
Subject: perl - CGI problem
Message-Id: <c360f580-5dab-4794-a259-09dbc7cbc750@56g2000hsm.googlegroups.com>

I wrote a perl program that retrieves data from MySQL database and do
some complex formating to export.  In the program I used some scalar
variables to hold temporary intermediate data (~2MB).

While this program works fine on command line (takes more than 10
minutes). When I adept it as a CGI program, it works only when a small
data set  is selected; When larger data set is selected, it fails
without error (return a blank page on web; no error to the Apache
server error log).

I wonder what could be the problem?  I suspect the internal scalar
variable may exceed some sort of internal memory limit but I really
don't know -- therefore seem advice from experts on what should I look
into?

Thanks in advance!
Zhiliang


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

Date: Tue, 02 Sep 2008 19:32:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl - CGI problem
Message-Id: <Xns9B0D9E170BE71asu1cornelledu@127.0.0.1>

Zhiliang Hu <zhilianghu@gmail.com> wrote in news:c360f580-5dab-4794-a259-
09dbc7cbc750@56g2000hsm.googlegroups.com:

> I wrote a perl program that retrieves data from MySQL database and do
> some complex formating to export.  In the program I used some scalar
> variables to hold temporary intermediate data (~2MB).
> 
> While this program works fine on command line (takes more than 10
> minutes). When I adept it as a CGI program, it works only when a small
> data set  is selected; When larger data set is selected, it fails
> without error (return a blank page on web; no error to the Apache
> server error log).
> 
> I wonder what could be the problem? 

See http://www.stonehenge.com/merlyn/LinuxMag/col39.html

Sinan

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

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: 02 Sep 2008 19:55:01 GMT
From: xhoster@gmail.com
Subject: Re: perl - CGI problem
Message-Id: <20080902155503.917$GS@newsreader.com>

Zhiliang Hu <zhilianghu@gmail.com> wrote:
> I wrote a perl program that retrieves data from MySQL database and do
> some complex formating to export.  In the program I used some scalar
> variables to hold temporary intermediate data (~2MB).
>
> While this program works fine on command line (takes more than 10
> minutes). When I adept it as a CGI program, it works only when a small
> data set  is selected; When larger data set is selected, it fails
> without error (return a blank page on web; no error to the Apache
> server error log).

1st guess: The web browser is not willing to wait 10 minutes to get its
answer. It gives up with a time out.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Tue, 02 Sep 2008 20:08:30 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Prolem examining JavaScript with SpiderMonkey.pm
Message-Id: <87od36774x.fsf@zeekat.nl>

Jan Schmidt <spam@jan-o-sch.net> writes:

> Hi all,
>
> I have the feeling I must have missed something in the documentation
> of JavaScript::SpiderMonkey. It seems to execute simple JavaScript
> fine. However, when generic browser elements like "window" or
> "document" are referenced, an error occurs.
>
> ReferenceError: document is not defined at line 0: (null)

That's because JavaScript::SpiderMonkey only interfaces with the
spidermonkey js interpreter. Which does not implement a browser model,
just the javascript core.

> I can work around this by creating such objects explicitly using the
> object_by_path() method:
>
>   use JavaScript::SpiderMonkey;
>   my $js = new JavaScript::SpiderMonkey;
>   $js->init();
>   my $document = $js->object_by_path("document");
>   $js->function_set("write", sub {print "JS> @_\n"}, $document);
>   $js->eval(qq{x=5; y=3; document.write(x+y);}) or die "js error: $@\n";
>
> Although this works, it does not seem practical to me. Is there any
> framework handling creation of objects existing in browsers?

Not as far as I know. You're probably much better off using
Mozilla::Mechanize, IE::Mechanize or WWW::Selenium, which run the
javascript code in an actual browser.

> The following js code also executes fine and prints "axc" as expecyed:
>   x=new String("abc"); y = x.replace(/b/, "x"); document.write(y);

Yes, that's part of the javscript core / ecmascript specification.

> In a browser, however, I could do something like this, which in
> SpiderMonkey would require implementing a self-written replace method
> for the object "window.location.href".
>   x=window.location.href.replace(/x/, "y");

I'm not sure what you'd expect that to do in SpiderMonkey, since there
is no window.

> I do not control the JavaScript I am going to inspect with
> SpiderMonkey. So this workaround (implementing methods for used
> objects in perl) seems unfeasible. It would be great if SpiderMonkey
> would know window.location.href exists *and* really can be used as a
> string with all its methods.

Changing the location of a window in a browser does quite a bit more
than just changing the properties of a string, so again, I'm not sure
what you actually want to achieve.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: 2 Sep 2008 18:26:57 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Prolem examining JavaScript with SpiderMonkey.pm
Message-Id: <Xns9B0D88D0AEB62castleamber@130.133.1.4>

Joost Diepenmaat <joost@zeekat.nl> wrote:

> Jan Schmidt <spam@jan-o-sch.net> writes:

[..]

>> I do not control the JavaScript I am going to inspect with
>> SpiderMonkey. So this workaround (implementing methods for used
>> objects in perl) seems unfeasible. It would be great if SpiderMonkey
>> would know window.location.href exists *and* really can be used as a
>> string with all its methods.
> 
> Changing the location of a window in a browser does quite a bit more
> than just changing the properties of a string, so again, I'm not sure
> what you actually want to achieve.

Maybe what I did some time ago: running JavaScript in a sandbox to find 
out where it redirects to. Blogspot, Geocities - to name a few - have been 
pestered for quite some time with this (JS). Google [1] and Yahoo don't 
seem to care much about it, but prefer to rely on external sources to 
report this (while they simply could automatically scan for this, or 
better: prevent it in the first place).

@Jan - if you're doing that, drop me an email, maybe we can work on it 
together :-).

[1] it took me weeks to find someone at Google who was willing to process 
the list I had compiled of thousands (!) of spamvertized blogs doing 
nothing but redirecting to actual sites of spammers.

-- 
John    http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html


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

Date: 02 Sep 2008 20:57:53 GMT
From: xhoster@gmail.com
Subject: using 2-arg open to open to a scalar
Message-Id: <20080902165755.862$vr@newsreader.com>

I'm looking for a value to put in $some_string so that the
below code will have $y read from $scalar.  I can't use the "<&4" syntax,
since $x doesn't have a real fileno to be duped.


open my $x, "<", \$scalar or die $!;
open my $y, $some_string or die $!;

The context of this is that I have an external (i.e. not my code) module
which won't take a file-handle, it will only take a "filename" which gets
passed to the 2-argument form of open.  So I want to craft a magical
"filename" that when given to 2-arg open, does what I want.

Thanks,

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Tue, 02 Sep 2008 22:46:24 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: using 2-arg open to open to a scalar
Message-Id: <4njvk.63412$hx.3593@pd7urf3no>

xhoster@gmail.com wrote:
> I'm looking for a value to put in $some_string so that the
> below code will have $y read from $scalar.  I can't use the "<&4" syntax,
> since $x doesn't have a real fileno to be duped.
> 
> 
> open my $x, "<", \$scalar or die $!;
> open my $y, $some_string or die $!;
> 
> The context of this is that I have an external (i.e. not my code) module
> which won't take a file-handle, it will only take a "filename" which gets
> passed to the 2-argument form of open.  So I want to craft a magical
> "filename" that when given to 2-arg open, does what I want.

It will work with a package filehandle:

$ perl -e'
$scalar = <<TEXT;
one two
three four
TEXT

open IN, "<", \$scalar or die $!;
open my $y, "<&=IN" or die $!;
print while <IN>;
print while <$y>;
'
one two
three four
one two
three four



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Tue, 02 Sep 2008 23:36:00 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: using 2-arg open to open to a scalar
Message-Id: <Xns9B0DC75D77FD1asu1cornelledu@127.0.0.1>

xhoster@gmail.com wrote in news:20080902165755.862$vr@newsreader.com:

> I'm looking for a value to put in $some_string so that the
> below code will have $y read from $scalar.  I can't use the "<&4"
> syntax, since $x doesn't have a real fileno to be duped.
> 
> 
> open my $x, "<", \$scalar or die $!;
> open my $y, $some_string or die $!;
> 
> The context of this is that I have an external (i.e. not my code)
> module which won't take a file-handle, it will only take a "filename"
> which gets passed to the 2-argument form of open.  So I want to craft
> a magical "filename" that when given to 2-arg open, does what I want.

C:\Temp> cat tt.pl
#!/usr/bin/perl
use strict;
use warnings;

use Alias;

my $input_text = <<EOT;
sdksdfk;lf';lk lk l;' k
asfas;l's' k' k'adkd;fka'gka' ' ksf'sg
;sk;sdkg;skg;sk
lsdf;ksdfk
EOT

open my $input, '<', \$input_text;
alias INPUT => $input;

myread( "<&=INPUT");

sub myread {
    my ($fn) = @_;

    open my $h, $fn or die $!;
    print while <$h>;
    return;
}

__END__

C:\Temp> tt
sdksdfk;lf';lk lk l;' k
asfas;l's' k' k'adkd;fka'gka' ' ksf'sg
;sk;sdkg;skg;sk
lsdf;ksdfk


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

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

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


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