[7140] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 766 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 24 04:17:13 1997

Date: Thu, 24 Jul 97 01:03:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 24 Jul 1997     Volume: 8 Number: 766

Today's topics:
     String Literals (Fan Ng)
     Re: String Literals (Eric Bohlman)
     Re: String Literals <clark@s3i.com>
     Re: Stumped by a regexp <mark@tstonramp.com>
     supressing output <gland@ccs.neu.edu>
     Re: Tie a hash of hashes ? (Jeff Stampes)
     Re: Unique File Creation Steve_Kilbane@cegelecproj.co.uk
     Re: Using varaibles from a template file <zenin@best.com>
     Re: Using varaibles from a template file <dear_andrew@jpmorgan.com>
     Re: What happens when.... <webmaster@restaurantdigest.com>
     Re: where to go for html and SSI questions <rootbeer@teleport.com>
     Re: Why won't this blessed thing destruct? (Chris Nandor)
     Re: Why: @{$_[0]} for arg in subroutine Steve_Kilbane@cegelecproj.co.uk
     Writing to a file descriptor (Dragomir R. Radev)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 23 Jul 1997 00:21:09 GMT
From: FANNGMAIL@prodigy.net (Fan Ng)
Subject: String Literals
Message-Id: <33d54e66.2264206@news.prodigy.net>

Hi all:

I'm reading a book which is called "Programming Perl Second Edition". And I
don't understant this paragraph what does he try to say, on page 39.

"double-quoted string literals are subject to backslash and variable
interpolation; single-quoted strings are not (except for \' and \\, so that you
can put single quotes and backslashes into single-quoted strings)."

can someone give me a example about this.

I tried this:
 
$a="fanfan";
$b='fan';

print $a,"\n";
print $b;

Output is    fanfan
                  fan

I can't see different and what the means in parenthesis??
Help me out thank you.
fangnmail@prodigy.net



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

Date: Wed, 23 Jul 1997 01:45:47 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: String Literals
Message-Id: <ebohlmanEDr0wB.Buo@netcom.com>

Fan Ng (FANNGMAIL@prodigy.net) wrote:

: I'm reading a book which is called "Programming Perl Second Edition". And I
: don't understant this paragraph what does he try to say, on page 39.

Thank you for taking some time to do your homework before asking a 
question here.

: "double-quoted string literals are subject to backslash and variable
: interpolation; single-quoted strings are not (except for \' and \\, so that you
: can put single quotes and backslashes into single-quoted strings)."

: can someone give me a example about this.

: I tried this:
:  
: $a="fanfan";
: $b='fan';

: print $a,"\n";
: print $b;

: Output is    fanfan
:                   fan

: I can't see different and what the means in parenthesis??

That's because none of your examples use backslash or variable 
interpolation.  Try changing the first two statements to:

$a="fanfan\n";
$b='fan\n';

and look at the output you get.  After that, add:

$c="It blows air twice: $a";
$d='It blows air once: $b";
print $c;
print $d;

and run it again.  You'll understand what Larry, Tom and Randal were 
talking about by then.



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

Date: 22 Jul 1997 21:44:17 -0400
From: Clark Dorman <clark@s3i.com>
Subject: Re: String Literals
Message-Id: <dpvsaee4u.fsf@s3i.com>


FANNGMAIL@prodigy.net (Fan Ng) writes:

> I'm reading a book which is called "Programming Perl Second
> Edition". And I don't understant this paragraph what does he try to
> say, on page 39.

Hey, good book!

> "double-quoted string literals are subject to backslash and variable
> interpolation; single-quoted strings are not (except for \' and \\,
> so that you can put single quotes and backslashes into single-quoted
> strings)."
>
> can someone give me a example about this.

Certainly, though you'll probably have to change the first line:

#!/home/dorman/bin/perl -w
# ^^^^^^^^^^^^^^^^^^^^^ change this for your location

# Play with single and double quotes, and interpolation.

$a = "fan";					  # variable
$b = "He is a big $a";				  # interpolates
$c = 'She is a big $a';				  # doesn't interpolate

$d = "This has tabs\t\t\tto here";		  # interpolates
$e = 'This does not have \t\t\ttabs';		  # doesn't interpolate

$f = "This has single ' quotes ' ' ' ";		  # single quotes ignored in doubles
$g = 'This has double " quotes " " " ';		  # double quotes ignored in singles

$h = 'Put a single quote in single \' quotes ';	  # Escape works for the single
$i = "Put a double quote in double \" quotes ";	  # Escape works for the double, too
                                                  # but you figured that, eh?

# Now, which one of these is going to work like we want??? Guess first!
print '\n  ($a)\n  ($b)\n  ($c)\n  ($d)\n  ($e)\n  ($f)\n  ($g)\n  ($h)\n  ($i)\n';
print "\n  ($a)\n  ($b)\n  ($c)\n  ($d)\n  ($e)\n  ($f)\n  ($g)\n  ($h)\n  ($i)\n";


> I tried this:
>  
> $a="fanfan";
> $b='fan';
> 
> print $a,"\n";
> print $b;
> 
> Output is    fanfan
>                   fan
> 
> I can't see different and what the means in parenthesis??

In _this_ context, they are identical.  But, if you try the above
little script, you'll see that they differ widely in certain contexts.

-- 
Clark Dorman				"Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html                -Francis Crick


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

Date: Wed, 23 Jul 1997 02:55:56 -0700
From: "Mark J. Schaal" <mark@tstonramp.com>
Subject: Re: Stumped by a regexp
Message-Id: <33D5D52C.7941@tstonramp.com>

Anneke Floor wrote:
> 
> The thing is, the filenames in this list can look like this:
>   file.www,xxx,yy
> if the file has multiple formats.
> I want it to match only one specified format.
>
[snip]
> 
> The first field in the record contains the filename. This field is
> delineated by "::". Is there any way to ensure the regexp doesn't look
> further than the first "::"?
> 

If there are no colons in the filenames, you should be able to
use something like this:

  m/^$prefix(?=\.)	# Lookahead for period, but don't use it yet
     [^:]*		# Match on non-colons, to stay within field
     [.,]		# Suffix must be preceed by one of these	
     $suffix
     [,:]		# If no padding on end, one of these follows suffix
   /x

which all together is m/^$prefix(?=\.)[^:]*[.,]$suffix[,:]/

I set it up with the delimeters around the suffix to prevent matching
similar suffixes.  For example, consider
	file.eps,psi
if we are looking for $suffix='ps'.

Hope this helps,

mark
--
Mark J. Schaal		TST On Ramp Sysadmin		mark@tstonramp.com


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

Date: 20 Jul 1997 21:45:13 GMT
From: Greg Land <gland@ccs.neu.edu>
Subject: supressing output
Message-Id: <5qu0t9$3q5$1@camelot.ccs.neu.edu>

Here is another problem I have... unrelated to the previos post.  I have a dos based file and want to remove the ^M's.  I know that the unix command to do this is dos2unix, but that prints out a message saying:

could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed

This is not a big deal, but I prefere it not be there.  does perl have its own dos2unix command or is there a way to redirect the output to somewhere that I do not see it?

							Thanks in advance

								Greg


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

Date: 22 Jul 1997 21:47:46 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Tie a hash of hashes ?
Message-Id: <5r39q2$k5g$1@neocad.com>

Calle Aasman (calle@studentREMOVETOREPLY.adb.gu.se) wrote:
: I would like to put a hash-of-hashes in a DBM, this can't be done, what
: are the options?

use MLDBM;

: Is there a way to use tie somehow?

Yup

: If anyone could help me out on this I would be very happy...

See the FAQ, specifically the question:

"How can I store a Multideimensional array in a DB File?"


--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


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

Date: Tue, 22 Jul 1997 08:58:56 GMT
From: Steve_Kilbane@cegelecproj.co.uk
To: "Karyl F. Stein" <steinkf@cs.purdue.edu>
Subject: Re: Unique File Creation
Message-Id: <7167cd$83a38.328@news.cegelecproj.co.uk>

In article <5r0cb5$549$0@206.85.222.24>, "Karyl F. Stein" <steinkf@cs.purdue.edu> writes:
> I am trying to write a subroutine that takes a seed, creates a unique
> file based on that seed, and returns the nme and a filehandle to the new
> file.

First question: are you using a recent-ish version of Perl5? If so, then
(a) why not just use POSIX::tmpnam?

	use POSIX qw(tmpnam)
	my $name = POSIX::tmpnam();

(b) why not use FileHandle?

	use FileHandle;
	my $fh = new FileHandle ">$filename";

(c) failing that, why not use Symbol?

	use Symbol;
	my $fh = gensym;
	open($fh, $filename);

So, I'd go for:

sub CreateFile {
	use POSIX qw(tmpnam);
	use FileHandle;
	my $name = POSIX::tmpnam();
	my $fh = new FileHandle $filename;
	( $name, $fh );
}
-- 
<Steve_Kilbane@cegelecproj.co.uk> - All opinions are mine alone.
Kilbane's law of integration: standardise on protocols and file
formats, and the applications take care of themselves.



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

Date: 24 Jul 1997 00:23:02 GMT
From: Zenin <zenin@best.com>
Subject: Re: Using varaibles from a template file
Message-Id: <5r6796$mvn$1@nntp2.ba.best.com>

Andrew Dear <dear_andrew@jpmorgan.com> wrote:
	>snip<
> I want to do the same thing as you have answered here, except
> my file might read:
> 	My name is $Const::names{'me'}
> instead of 
> 	My name is $my_name
> Try as might I can't change the regular expression and get it
> to match correctly.

	Well this isn't pretty, but it works better then a regexp
	of any kind:

		$template = eval qq(<<"EndOfEval";\n$template\nEndOfEval\n);

	Let perl do the hard work of parsing it.  This also allows for
	all the extreamly complex interpalation(sp?) that is posible
	with perl.  Ie, kool stuff like this will work fine:

		My name is $Const::names{'me'}
		Today's date is @{[ scalar localtime(time) ]}

	The only restriction is that the "EndOfEval" be unique enough so
	that it doesn't have a chance of messing up the eval.

	Hope this helps!

-- 
-Zenin
 Quake Clan After Shock (Did you feel that?)
 The Bawdy Cast - Rocky Horror Picture Show (San Jose, CA)
 Zenin's Rocky Archive (http://www.best.com/~zenin/)
 zenin@best.com


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

Date: Wed, 23 Jul 1997 15:41:00 -0700
From: Andrew Dear <dear_andrew@jpmorgan.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Using varaibles from a template file
Message-Id: <33D6887C.77BE@jpmorgan.com>

Tom Phoenix wrote:
> 
> On Sat, 19 Jul 1997, Tung-chiang Yang wrote:
> 
> > Tom Phoenix wrote after zapping the scum of the universe:
> 
> > :     $template =~ s/(\$\w+)/$1/gee;  # Maybe what you want?
> >
> > Is there any special effect of using 'gee' instead of 'ge'?
> 
> Yes, there is. Try it and see. Hope this helps!
> 
> --
> Tom Phoenix           http://www.teleport.com/~rootbeer/
> rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
> Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/

I want to do the same thing as you have answered here, except
my file might read:

	My name is $Const::names{'me'}

instead of 

	My name is $my_name

ie. instead of a variable in the file (eg. $name) I have
a hash declared in another package (eg. $Const::names{'me'})

Try as might I can't change the regular expression and get it
to match correctly.

Any help would be much appreciated.


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

Date: Tue, 22 Jul 1997 20:27:06 +0000
From: Mark McDonald <webmaster@restaurantdigest.com>
Subject: Re: What happens when....
Message-Id: <33D51799.1B80@restaurantdigest.com>

You need to use the "flock" function if your server supports it.

This will  lock the file so it can't be written/appended by two people
at the same time... Something like this:

sub get_file_lock
  {
 flock(LOCK_FILE, 2); # 2 exclusively locks the file
  }

#######################################################################
#                            release_file_lock                       
#     
#######################################################################

                # release_file_lock is the partner of get_file_lock. 
When
                # an instance of this script is done using the file it
                # needs to manipulate, it calls release_file_lock to
                # delete the lock file that it put in place so that
other
                # instances of the script can get to the shared file. 
It
                # takes one argument, the name of the lock file, and is
                # called with the following syntax:
                #
                # &release_file_lock("file.name");

sub release_file_lock
  {
 flock(LOCK_FILE, 8); # 8 unlocks the file
 }


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

Date: Tue, 22 Jul 1997 23:36:35 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Raj Kumar <rajk@best.com>
Subject: Re: where to go for html and SSI questions
Message-Id: <Pine.GSO.3.96.970722233344.23134N-100000@kelly.teleport.com>

On Tue, 22 Jul 1997, Raj Kumar wrote:

> I was wondering what is the right newsgroup to go to
> for html and server side include questions.

Here are the ones I usually recommend. Some people may have other
preferences, and there may be other groups available from your site. 
Thanks for asking! 

    comp.infosystems.www.authoring.html - Writing HTML for the Web.

    comp.infosystems.www.Servers.mac - Web servers for the Macintosh
       platform.

    comp.infosystems.www.Servers.ms-windows - Web servers for MS
       Windows and NT.

    comp.infosystems.www.Servers.unix - Web servers for UNIX
       platforms.

    comp.infosystems.www.Servers.misc - Web servers for other
       platforms.

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 23 Jul 1997 08:58:34 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Why won't this blessed thing destruct?
Message-Id: <pudge-ya02408000R2307970858340001@news.idt.net>

In article <slrn5sfa7i.g8c.andrew@pimlott.student.harvard.edu>,
pimlott@math.harvard.edu wrote:

# I am getting a situation in which (it appears) that a blessed object is not
# calling its DESTROY method when it goes out of scope.  Consider the
# following script:

# {
#         my $joe;
#         my $moe = bless \$joe, 'mytest';
[...]
# }

Perhaps related to Blue Camel p. 299?  The reference count has to go to
zero before it can be destroyed.

--
Chris Nandor             pudge@pobox.com             http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])


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

Date: Tue, 22 Jul 1997 17:15:27 GMT
From: Steve_Kilbane@cegelecproj.co.uk
To: sajjad@uic.edu
Subject: Re: Why: @{$_[0]} for arg in subroutine
Message-Id: <7167cd$11f1b.37@news.cegelecproj.co.uk>

[ Copy mailed ]

In article <5qjle3$30vk$1@piglet.cc.uic.edu>, sajjad@uic.edu (Sajjad Lateef) writes:
> my @color_array = [ 'Red', 'Blue', 'Yellow'];

Wrong brackets. Use ( ... ) instead of [ ... ]. Instead of assigning the colours
list to color_array, you're creating the list anonymously and obtaining a
reference to it, and then assigning a list consisting solely of that reference to
color_array.

I've done similar things myself with hashes, using { ... } to create
anon hashes, when I meant ( ... ).

steve
-- 
<Steve_Kilbane@cegelecproj.co.uk> - All opinions are mine alone.
Kilbane's law of integration: standardise on protocols and file
formats, and the applications take care of themselves.



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

Date: 23 Jul 1997 13:31:26 -0400
From: radev@news.cs.columbia.edu (Dragomir R. Radev)
Subject: Writing to a file descriptor
Message-Id: <5r5f5e$24n@bluewhale.cs.columbia.edu>

1. Is there a function that does the opposite to fileno: namely, return a
filehandle given a file descriptor?

2. Is there a way for a Perl process to write to a specified (inherited) file
descriptor without opening a file for it?

3. Is there any other solution to the problem described below? Perhaps
using dup?

The context is the following: I am using perlembed and I want the perl code
to write to a file descriptor that has already been open by the C code. I
don't want to open a file explicitly from Perl, as that file and the
associated file descriptor will be closed when the perl interpreter exits
and I will need to reuse the file descriptor from the C code.

Thanks,


Drago

-- 
Dragomir R. Radev                           Graduate Research Assistant
Natural Language Processing Group     Columbia University CS Department
H: 212-749-9770  O: 212-939-7121      http://www.cs.columbia.edu/~radev


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 766
*************************************

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