[28130] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9494 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 14:05:47 2006

Date: Tue, 18 Jul 2006 11:05:07 -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, 18 Jul 2006     Volume: 10 Number: 9494

Today's topics:
    Re: A subroutine for gcd <gamo@telecable.es>
        commenting configuration files <nmrabinovich@gmail.com>
    Re: commenting configuration files xhoster@gmail.com
        Creating a new file something going wrong <riderchap@gmail.com>
    Re: Creating a new file something going wrong <jue@monster-berlin.de>
    Re: Creating a new file something going wrong <no@email.com>
    Re: Creating a new file something going wrong <tzz@lifelogs.com>
    Re: Creating a new file something going wrong <riderchap@gmail.com>
        Hashes of hashes? <asincero@gmail.com>
    Re: Hashes of hashes? <daleif@RTFSIGNATUREimf.au.dk>
    Re: Hashes of hashes? <David.Squire@no.spam.from.here.au>
    Re: Hashes of hashes? <asincero@gmail.com>
        How to find which (if any) member of a list is in a giv tinnews@leary.csoft.net
    Re: How to find which (if any) member of a list is in a <tzz@lifelogs.com>
        numeric sort on string like a123-3 <filippo2991@virgilio.it>
        perl and threads <compaqnet.be@kristoff.bonne>
    Re: perl and threads xhoster@gmail.com
    Re: please urgent <mritty@gmail.com>
        secure login <robert.pena@gmail.com>
    Re: secure login <no@email.com>
        start printing at the end of the previous line <weberw@adelphia.net>
    Re: start printing at the end of the previous line <jurgenex@hotmail.com>
    Re: start printing at the end of the previous line <David.Squire@no.spam.from.here.au>
    Re: start printing at the end of the previous line <weberw@adelphia.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 18 Jul 2006 16:09:07 +0200
From: gamo <gamo@telecable.es>
Subject: Re: A subroutine for gcd
Message-Id: <Pine.LNX.4.64.0607181606030.19445@jvz.es>

On Tue, 18 Jul 2006, Michele Dondi wrote:

> On Mon, 17 Jul 2006 15:38:58 +0200, gamo <gamo@telecable.es> wrote:
> 
> >Does anyone knows how to write a sub for gcd?
> 
> Yes I know!
> 
> Ok, now I know you don't believe me...
> 
>   sub gcd { $_[1]?gcd($_[1],$_[0]%$_[1]):$_[0] }
> 
I belive you, but it is just a gcd of a PAIR of numbers.

I find this in the ToolBox module

sub gcd {
        use integer;
        my $gcd = shift || 1;
        while (@_) {
                my $next = shift;
                while($next) {
                        my $r = $gcd % $next;
                        $r += $next if $r < 0;
                        $gcd = $next;
                        $next = $r;
                }
        }
        no integer;
        return $gcd;
}

Cheers,



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

Date: 18 Jul 2006 09:46:44 -0700
From: "lnatz" <nmrabinovich@gmail.com>
Subject: commenting configuration files
Message-Id: <1153241204.777711.92010@s13g2000cwa.googlegroups.com>

how do you properly comment a configuration file? I just finished
writing a perl script and I used a configuration file to hold specific
details that would change like a user id and names of files. I need to
comment the configuration file but I am not absolutely positive how to
go about that.



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

Date: 18 Jul 2006 16:47:44 GMT
From: xhoster@gmail.com
Subject: Re: commenting configuration files
Message-Id: <20060718125249.762$Kk@newsreader.com>

"lnatz" <nmrabinovich@gmail.com> wrote:
> how do you properly comment a configuration file?

The proper way to comment a configuration file is to use the method
provided for comments by the configuration parser.  Since you don't
say how you are parsing your configuration file, we have no idea what
that might be.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 18 Jul 2006 08:30:49 -0700
From: "riderchap@gmail.com" <riderchap@gmail.com>
Subject: Creating a new file something going wrong
Message-Id: <1153236649.495497.291180@m79g2000cwm.googlegroups.com>

I am opening a new file and writing something to that file and then
closing it. Now note down the size of file, let it be n bytes.
Then when I open the newly created file using vi make a change undo
that change and save and close it, now see the size of the file is n+1
bytes.

Also when I open the Perl program generated file in vi, vi will say
"Last line is not complete", why is that? After the
change-undo-save-close by vi, when I reopen the file in vi the vi is
not saying "Last line is not complete".

Here is the sample test script I used.

open (OUT_FILE, ">testfile");
print OUT_FILE "Hello World";
close (OUT_FILE);

After Perl program run the size of file is 11bytes. (Hello World is 11
characters). After opening in vi insert a charater then delete that
character then save and close. Now the file size is showing as 12
bytes.
What is vi writing there?
Or what character is my Perl program missing to write?
Why vi says "Last line is not complete", when opening the file created
by the Perl program?

Thanks!!!!!!!
Kannan

Note: The file I create through my Perl program has to be used by
another C program and that C program is not reading the last line of
the file correctly. Please help.



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

Date: 18 Jul 2006 08:38:31 -0700
From: "jue" <jue@monster-berlin.de>
Subject: Re: Creating a new file something going wrong
Message-Id: <1153237111.151544.124050@h48g2000cwc.googlegroups.com>

riderchap@gmail.com schrieb:

>
> open (OUT_FILE, ">testfile");
> print OUT_FILE "Hello World";
> close (OUT_FILE);
>
> After Perl program run the size of file is 11bytes. (Hello World is 11
> characters). After opening in vi insert a charater then delete that
> character then save and close. Now the file size is showing as 12
> bytes.
> What is vi writing there?

vi writes a "\n" at the end of your "incomplete" line.

Thomas



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

Date: Tue, 18 Jul 2006 16:40:15 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Creating a new file something going wrong
Message-Id: <4i4dmvF22s0lU1@individual.net>

riderchap@gmail.com wrote:

> I am opening a new file and writing something to that file and then
> closing it. Now note down the size of file, let it be n bytes.
> Then when I open the newly created file using vi make a change undo
> that change and save and close it, now see the size of the file is n+1
> bytes.
> 
> Also when I open the Perl program generated file in vi, vi will say
> "Last line is not complete", why is that? After the
> change-undo-save-close by vi, when I reopen the file in vi the vi is
> not saying "Last line is not complete".
> 
> Here is the sample test script I used.
> 
> open (OUT_FILE, ">testfile");
> print OUT_FILE "Hello World";
> close (OUT_FILE);
> 
> After Perl program run the size of file is 11bytes. (Hello World is 11
> characters). After opening in vi insert a charater then delete that
> character then save and close. Now the file size is showing as 12
> bytes.
> What is vi writing there?
> Or what character is my Perl program missing to write?
> Why vi says "Last line is not complete", when opening the file created
> by the Perl program?
> 
> Thanks!!!!!!!
> Kannan
> 
> Note: The file I create through my Perl program has to be used by
> another C program and that C program is not reading the last line of
> the file correctly. Please help.


The character will almost certainly be a line feed (ASCII 10).

I don't see why the C program should have a problem with this unless it is
written in such a way that it needs each line to end with a line feed, in
which case make sure you write one at the end of each line in the file.

print OUT_FILE "Hello World\n";

-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: Tue, 18 Jul 2006 11:44:04 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Creating a new file something going wrong
Message-Id: <g69psg2vry3.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 18 Jul 2006, riderchap@gmail.com wrote:

> I am opening a new file and writing something to that file and then
> closing it. Now note down the size of file, let it be n bytes.
> Then when I open the newly created file using vi make a change undo
> that change and save and close it, now see the size of the file is n+1
> bytes.
>
> Also when I open the Perl program generated file in vi, vi will say
> "Last line is not complete", why is that? After the
> change-undo-save-close by vi, when I reopen the file in vi the vi is
> not saying "Last line is not complete".
>
> Here is the sample test script I used.
>
> open (OUT_FILE, ">testfile");
> print OUT_FILE "Hello World";
> close (OUT_FILE);
>
> After Perl program run the size of file is 11bytes. (Hello World is 11
> characters). After opening in vi insert a charater then delete that
> character then save and close. Now the file size is showing as 12
> bytes.
> What is vi writing there?
> Or what character is my Perl program missing to write?
> Why vi says "Last line is not complete", when opening the file created
> by the Perl program?

The last line is not complete (according to vi) because it doesn't end
with a newline character.  vi appended it.

Here's the easy way to see the difference:

> perl -e'open (OUT_FILE, ">testfile"); print OUT_FILE "Hello World";'
> cat testfile
Hello World> vi testfile
 ... insert and then delete a character, then save ...
> cat testfile
Hello World
>

See how the file ends with a newline the second time?

You can print "Hello World\n" in line 2 of your code to achieve the
same result.

Ted


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

Date: 18 Jul 2006 09:00:01 -0700
From: "riderchap@gmail.com" <riderchap@gmail.com>
Subject: Re: Creating a new file something going wrong
Message-Id: <1153238401.449610.255970@p79g2000cwp.googlegroups.com>

Thanks folks!!!

I tried all crap ctl Z etc... don't know why didn't try a simple "\n".

Brian Wakem, that C program is written by somebody else and I have to
dig out that big C program to find out what he is doing there.

Thanks again guys.

-Kannan


Ted Zlatanov wrote:
> On 18 Jul 2006, riderchap@gmail.com wrote:
>
> > I am opening a new file and writing something to that file and then
> > closing it. Now note down the size of file, let it be n bytes.
> > Then when I open the newly created file using vi make a change undo
> > that change and save and close it, now see the size of the file is n+1
> > bytes.
> >
> > Also when I open the Perl program generated file in vi, vi will say
> > "Last line is not complete", why is that? After the
> > change-undo-save-close by vi, when I reopen the file in vi the vi is
>



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

Date: 18 Jul 2006 08:04:56 -0700
From: "asincero" <asincero@gmail.com>
Subject: Hashes of hashes?
Message-Id: <1153235096.271059.226320@75g2000cwc.googlegroups.com>

I have this:

use strict;
my %my_hash = ();

$my_hash{'1'}{'a'} = "Hello";
$my_hash{'1'}{'b'} = "world!";
$my_hash{'2'}{'c'} = "Foo";
$my_hash{'2'}{'d'} = "bar";

And I want to do something like this:

foreach my $k (keys $my_hash{'1'})
{
   print "$k\n";
}

Should give the output of:
a
b

But of course the above code is wrong.  How do I correct it?

Thanks.

-- Arcadio



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

Date: Tue, 18 Jul 2006 17:12:19 +0200
From: Lars Madsen <daleif@RTFSIGNATUREimf.au.dk>
Subject: Re: Hashes of hashes?
Message-Id: <e9itoj$ej0$2@news.net.uni-c.dk>

asincero wrote:
> I have this:
> 
> use strict;
> my %my_hash = ();
> 
> $my_hash{'1'}{'a'} = "Hello";
> $my_hash{'1'}{'b'} = "world!";
> $my_hash{'2'}{'c'} = "Foo";
> $my_hash{'2'}{'d'} = "bar";
> 
> And I want to do something like this:
> 
> foreach my $k (keys $my_hash{'1'})
> {
>    print "$k\n";
> }
> 
> Should give the output of:
> a
> b
> 
> But of course the above code is wrong.  How do I correct it?
> 
> Thanks.
> 
> -- Arcadio
> 

do what the compiler tells you

use %{ $my_hash{'1'} }

-- 

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ:      http://www.tex.ac.uk/faq
LaTeX book:     http://www.imf.au.dk/system/latex/bog/    (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl


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

Date: Tue, 18 Jul 2006 16:19:58 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Hashes of hashes?
Message-Id: <e9iu6v$s8i$1@gemini.csx.cam.ac.uk>

asincero wrote:
> I have this:
> 
> use strict;
> my %my_hash = ();
> 
> $my_hash{'1'}{'a'} = "Hello";
> $my_hash{'1'}{'b'} = "world!";
> $my_hash{'2'}{'c'} = "Foo";
> $my_hash{'2'}{'d'} = "bar";
> 
> And I want to do something like this:
> 
> foreach my $k (keys $my_hash{'1'})
> {
>    print "$k\n";
> }
> 
> Should give the output of:
> a
> b
> 
> But of course the above code is wrong.  How do I correct it?
> 

What does Perl tell you? The error message is:

	Type of arg 1 to keys must be hash (not hash element) at ./test.pl line 
13, near "})
"

So, Perl is telling you what the problem is. $my_hash{'1'} is a hash 
element, which in this case stores a *reference* to a hash (see perldoc 
perldsc). You need to dereference it. What you want is:

----

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

my %my_hash = ();

$my_hash{'1'}{'a'} = "Hello";
$my_hash{'1'}{'b'} = "world!";
$my_hash{'2'}{'c'} = "Foo";
$my_hash{'2'}{'d'} = "bar";

foreach my $k (keys %{$my_hash{'1'}})
{
    print "$k\n";
}

----

Output:

a
b


DS


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

Date: 18 Jul 2006 08:52:20 -0700
From: "asincero" <asincero@gmail.com>
Subject: Re: Hashes of hashes?
Message-Id: <1153237940.825639.33880@35g2000cwc.googlegroups.com>

Thanks guys.  I guess I didn't understand what Perl was trying to tell
me.

-- Arcadio


David Squire wrote:
> asincero wrote:
> > I have this:
> >
> > use strict;
> > my %my_hash = ();
> >
> > $my_hash{'1'}{'a'} = "Hello";
> > $my_hash{'1'}{'b'} = "world!";
> > $my_hash{'2'}{'c'} = "Foo";
> > $my_hash{'2'}{'d'} = "bar";
> >
> > And I want to do something like this:
> >
> > foreach my $k (keys $my_hash{'1'})
> > {
> >    print "$k\n";
> > }
> >
> > Should give the output of:
> > a
> > b
> >
> > But of course the above code is wrong.  How do I correct it?
> >
>
> What does Perl tell you? The error message is:
>
> 	Type of arg 1 to keys must be hash (not hash element) at ./test.pl line
> 13, near "})
> "
>
> So, Perl is telling you what the problem is. $my_hash{'1'} is a hash
> element, which in this case stores a *reference* to a hash (see perldoc
> perldsc). You need to dereference it. What you want is:
>
> ----
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my %my_hash = ();
>
> $my_hash{'1'}{'a'} = "Hello";
> $my_hash{'1'}{'b'} = "world!";
> $my_hash{'2'}{'c'} = "Foo";
> $my_hash{'2'}{'d'} = "bar";
>
> foreach my $k (keys %{$my_hash{'1'}})
> {
>     print "$k\n";
> }
> 
> ----
> 
> Output:
> 
> a
> b
> 
> 
> DS



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

Date: 18 Jul 2006 15:08:56 GMT
From: tinnews@leary.csoft.net
Subject: How to find which (if any) member of a list is in a given line of text
Message-Id: <44bcf988$0$781$bed64819@news.gradwell.net>

Are there any cleaner/quicker ways of doing the following:-

    @fs = ("string1", "string2", "string3", "string4");

    foreach $f (@fs)
    {
	if (index ($line, $f)
	{
	    # do something useful
	}
    }

Sorry if the syntax isn't quite right but I'm sure the idea is fairly
clear.  The strings to search for (@fs) are read from a file once only
and are essentially constant, they can be in an array or a hash or
whatever is most efficient.

The line to search comes from standard input and is the 'variable'
in the problem.

So I'm receiving lines of text and I want to do something whenever
one of my 'constant' strings is found in that line.    

-- 
Chris Green


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

Date: Tue, 18 Jul 2006 11:48:54 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to find which (if any) member of a list is in a given line of text
Message-Id: <g69lkqqvrq1.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 18 Jul 2006, tinnews@leary.csoft.net wrote:

> Are there any cleaner/quicker ways of doing the following:-
>
> @fs = ("string1", "string2", "string3", "string4");
>
> foreach $f (@fs)
> {
> 	if (index ($line, $f)
> 	{
> 	    # do something useful
> 	}
> }
>
> Sorry if the syntax isn't quite right but I'm sure the idea is fairly
> clear.  The strings to search for (@fs) are read from a file once only
> and are essentially constant, they can be in an array or a hash or
> whatever is most efficient.
>
> The line to search comes from standard input and is the 'variable'
> in the problem.
>
> So I'm receiving lines of text and I want to do something whenever
> one of my 'constant' strings is found in that line.    

You can also make a complicated regex (you need to qr// and then join)
to match, then study() it and maybe it will be a little faster, but
this way is probably easiest.  Just put a last() inside your if()
block to skip any tests you don't need to make (if that's the right
logic).

If the search strings have commonalities, you can search for that, and
skip lines that don't contain it.  I doubt it's worth the effort.
Generally, go for the simplest solution unless it's slow :)

Ted


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

Date: 18 Jul 2006 11:01:20 -0700
From: "filippo" <filippo2991@virgilio.it>
Subject: numeric sort on string like a123-3
Message-Id: <1153245680.602150.88320@m79g2000cwm.googlegroups.com>

Hi,
I have string lilke these

a12-1
b1-3
b123-2
c12
c12-1

axxx-y

a is a letter
xxx is a number 1-120
y is a number 1-3

I want to sort by xxx, is it possible?



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

Date: Tue, 18 Jul 2006 15:20:42 +0200
From: kristoff bonne <compaqnet.be@kristoff.bonne>
Subject: perl and threads
Message-Id: <44bce02a$0$5529$ba620e4c@news.skynet.be>

Aan allen die zijn of zullen zijn, onze groet.



I don't know if this is the correct place for this, but I'm looking for 
some information about perl threads.

I've been looking into perlthrtut and the other manuals for this, but I 
don't see to find the solution.

If it is off-topic, please point me to a more correct newsgroup or forum.


My question is this:

Is there a way to get 100 % certainty if a thread is running.


What I want to do is this:

I have a program that makes a number (actually eigth) of ssh-sessions to 
a number of servers using the net::telnet module. On the servers, they 
read the log-files to get some information using a "tail -f".


Now, I've got a thread (called "sshmaster") in my main program which 
starts up the 8 ssh-session (called "sshsession"); each as a seperate 
thread.
These sub-thread communicate back to "sshmaster" for control-messages 
(e.g. connection established, connection failed, connection interrupted) 
  using a queue.



So far, so good. And it does seams to work pretty-much OK, ... as long 
as the ssh-sessions behaviour as they are supposted to do.


But, I want to be sure that the sub-threads do keep on working OK, and 
-when a subtreads dies for whatever reason- that "sshmaster" is able to 
check this.

I see different possibilities:
1/ sent a control-message from the sub-thread to sshmaster over the 
message-queue. However, this will not work if the subthread dies for an 
unknown reason and it might not be able to sent a message to sshmaster.

2/ lock a variable (which will automatically unlock when the thread 
dies), but sshmaster is not able to check if a variable is still locked 
without blocking.

3/ As "sshmaster" has a list of all its subthreads, ask a system if a 
thread is still alive. But HOW????


The only way I see is by locking a file using the "flock" mechanism but 
that'a a bit "overkill" if you ask me.




Anybody any other ideas?



Cheerio! Kr. Bonne.


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

Date: 18 Jul 2006 15:34:25 GMT
From: xhoster@gmail.com
Subject: Re: perl and threads
Message-Id: <20060718113930.401$GC@newsreader.com>

kristoff bonne <compaqnet.be@kristoff.bonne> wrote:
>
> 3/ As "sshmaster" has a list of all its subthreads, ask a system if a
> thread is still alive. But HOW????

Thread::State

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 18 Jul 2006 07:17:37 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: please urgent
Message-Id: <1153232257.696226.288960@75g2000cwc.googlegroups.com>

jeni wrote:
> how to read ms word document and manipulate the document using
> win32::OLE.

Please read the Posting Guidelines for this group.  They are posted
here twice a week.  Take from them the following information:
* Put the subject of your post in the Subject of your post.  Your post
is not about "please urgent", it is about manipulating Word documents
with Win32::OLE
* Your problem is not "urgent" to anyone from whom you are seeking
assistance.  It is not our problem that you or your company did not
allocate the right amount of time or right resources to your task.
Telling us that your problem is "urgent" is rude.  If it's that urgent,
hire a consultant who actually knows Perl.
* Make an attempt to solve your problem first.  If you have made an
attempt, but it is failing, post a SHORT but COMPLETE script that
demonstrates the failure.
* Describe in as much detail as possible what the error is.  Especially
include the error messages, desired output, and actual output.
* If you haven't made an attempt yet, read the documentation for the
module you're using, and at least *try*.  In your case, said
documentation is found at:
http://search.cpan.org/~jdb/libwin32-0.26/OLE/lib/Win32/OLE.pm
* Do a search of CPAN to see if there are any modules better suited to
your task.  For example, how about
http://search.cpan.org/~johanl/Win32-Word-Writer-0.02/lib/Win32/Word/Writer.pm
?

Paul Lalli



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

Date: 18 Jul 2006 09:46:19 -0700
From: "probert" <robert.pena@gmail.com>
Subject: secure login
Message-Id: <1153241179.787025.30510@m79g2000cwm.googlegroups.com>

Hi all,

    I was wondering if anyone had some info about logging into a secure
site that uses javascript. I get an error saying that I need to have
javascript enabled to use the site. I wonder if I need the
WWW-IE-Mechanize module for this, but not sure. Any info would be
great. Thanks.

 ps. I am using WWW-Mechanize to do the login.



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

Date: Tue, 18 Jul 2006 18:30:19 +0100
From: Brian Wakem <no@email.com>
Subject: Re: secure login
Message-Id: <4i4k5bF24c4bU1@individual.net>

probert wrote:

> Hi all,
> 
>     I was wondering if anyone had some info about logging into a secure
> site that uses javascript. I get an error saying that I need to have
> javascript enabled to use the site. I wonder if I need the
> WWW-IE-Mechanize module for this, but not sure. Any info would be
> great. Thanks.
> 
>  ps. I am using WWW-Mechanize to do the login.


It depends what they are using JS for.  Usually you need to inspect the JS
code and mimic it's intended behaviour.


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: 18 Jul 2006 07:37:14 -0700
From: "weberw@adelphia.net" <weberw@adelphia.net>
Subject: start printing at the end of the previous line
Message-Id: <1153233434.107134.218320@b28g2000cwb.googlegroups.com>

Does anyone know who to tab to then end of the previous line in Perl?
apple, banana and orange would start on the next line where the "s" in
fruits ends.

Example,  Output to the screen would look like this..


fruits
      apple
       banana
       orange



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

Date: Tue, 18 Jul 2006 14:59:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: start printing at the end of the previous line
Message-Id: <KH6vg.7744$rT6.2567@trnddc03>

weberw@adelphia.net wrote:
> Does anyone know who to tab to then end of the previous line in Perl?
> apple, banana and orange would start on the next line where the "s" in
> fruits ends.
>
> Example,  Output to the screen would look like this..
>
>
> fruits
>      apple
>       banana
>       orange

use strict; use warnings;
print "fruits\n";
print ' 'x (length('fruits')-1), "apple\n";
print ' 'x length('fruits'), "banana\n";
print ' 'x length('fruits'), "orange\n";

jue




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

Date: Tue, 18 Jul 2006 16:06:28 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: start printing at the end of the previous line
Message-Id: <e9itdl$qkr$1@gemini.csx.cam.ac.uk>

weberw@adelphia.net wrote:
> Does anyone know who to tab to then end of the previous line in Perl?
> apple, banana and orange would start on the next line where the "s" in
> fruits ends.
> 
> Example,  Output to the screen would look like this..
> 
> 
> fruits
>       apple
>        banana
>        orange
> 

Hmmm. Do you really want not to use standard tabs? If so:

----

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

my $category = 'fruits';
my @members = qw(apple banana orange);

print "$category\n";
for (@members) {
	print ' ' x length $category;
	print "$_\n";
}

----

Output:

fruits
       apple
       banana
       orange


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

Date: 18 Jul 2006 09:50:04 -0700
From: "weberw@adelphia.net" <weberw@adelphia.net>
Subject: Re: start printing at the end of the previous line
Message-Id: <1153241404.359927.14940@i42g2000cwa.googlegroups.com>

Thanks David,    It still prints everything on one line.  Can you take
a look at my code...

#!C://Perl/bin/perl
use CGI ':standard';
use CGI::Carp  'fatalsToBrowser';
use strict;
use warnings;
use File::Find;
my $file_count = 0;
my $dir_count = 0;
my $title;
my $directorylen;

$title = "Find Files";
print header,
	start_html($title),
	h1($title);



find ( {
  wanted => \&wanted}, 'C:/Documents and
Settings/whatever/Desktop/test');


printf "\nThere are %d files in %d directories.\n",
$file_count,
$dir_count;

sub wanted {

		if(-d){
			return if $File::Find::name =~ /test3/;

			#get the length of the directory
			#so the files contained in the folder
			#can start printing at the end
			#of the directory name

			$directorylen = length($_);
			print "$_\n\n";



    $dir_count++;
}
elsif (-f _) {
	  			return if $File::Find::name =~ /test3/;
			 	print ' ' x ($directorylen-1), $_;
 	  			print ("\n\n\n")
				$file_count++;
    
}
} 


print end_hmtl;



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

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 V10 Issue 9494
***************************************


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