[30135] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1378 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 20 21:09:47 2008

Date: Thu, 20 Mar 2008 18:09:09 -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           Thu, 20 Mar 2008     Volume: 11 Number: 1378

Today's topics:
        64 Bit integer display <pradeep.bg@gmail.com>
    Re: 64 Bit integer display <joost@zeekat.nl>
    Re: 64 Bit integer display <ben@morrow.me.uk>
    Re: better design of spreadsheet generation <ela@yantai.org>
        generic declaration of variables <ela@yantai.org>
    Re: generic declaration of variables sandy_saydakov@yahoo.com
    Re: generic declaration of variables <benkasminbullock@gmail.com>
    Re: Is substr only way of getting nth character of stri <see.my.signature@for.my.email.address>
    Re: Is substr only way of getting nth character of stri <uri@stemsystems.com>
    Re: Strange syntex: beginner <jainarunk@gmail.com>
    Re: Strange syntex: beginner <glex_no-spam@qwest-spam-no.invalid>
    Re: Strange syntex: beginner <tadmc@seesig.invalid>
    Re: strategies other than subroutine and OO? <tadmc@seesig.invalid>
    Re: strategys other than subroutine and OO? <john@castleamber.com>
    Re: strategys other than subroutine and OO? xhoster@gmail.com
    Re: strategys other than subroutine and OO? <devnull4711@web.de>
    Re: strategys other than subroutine and OO? <john@castleamber.com>
    Re: strategys other than subroutine and OO? <cartercc@gmail.com>
    Re: strategys other than subroutine and OO? <ben@morrow.me.uk>
    Re: strategys other than subroutine and OO? <abigail@abigail.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 20 Mar 2008 13:04:55 -0700 (PDT)
From: Deepu <pradeep.bg@gmail.com>
Subject: 64 Bit integer display
Message-Id: <aae7f6dd-175b-4493-8482-befa4e640e2f@s13g2000prd.googlegroups.com>

Hi All,

Can somebody give some ideas on how to display 64bit integer.

I tried,

#!/usr/bin/perl -w

use bigint;

$test = 0x123456789abcdef;

print "$test \n";

But when i run:

Hexadecimal number > 0xffffffff not portable

Thanks!



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

Date: Thu, 20 Mar 2008 21:25:51 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: 64 Bit integer display
Message-Id: <8763vh3zxs.fsf@zeekat.nl>

Deepu <pradeep.bg@gmail.com> writes:

> Hexadecimal number > 0xffffffff not portable

is that really the error you get? it works for every perl I've got on
linux that has bigint. (in my case, perls 5.8.5 ... 5.10 ) and I can't
find ANY reference to that error using google.

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


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

Date: Thu, 20 Mar 2008 20:41:44 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: 64 Bit integer display
Message-Id: <8puab5-vtf.ln1@osiris.mauzo.dyndns.org>


Quoth Deepu <pradeep.bg@gmail.com>:
> 
> I tried,
> 
> #!/usr/bin/perl -w
> 
> use bigint;
> 
> $test = 0x123456789abcdef;
> 
> print "$test \n";
> 
> But when i run:
> 
> Hexadecimal number > 0xffffffff not portable

perldiag tells you this warning is in the 'portable' category. Since the
only warnings in this category are about integers greater than 2**32-1,
which you aren't interested in, simply turn them off:

    use warnings;
    use strict;

    no warnings 'portable';
    use bigint;

    print 0x123456789abcdef;

At least on my perl (i386-freebsd-64int), I don't need 'bigint', since
despite being built for a 32-bit processor it can still use 64-bit
integers.

Ben



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

Date: Fri, 21 Mar 2008 06:58:46 +0800
From: "Ela" <ela@yantai.org>
Subject: Re: better design of spreadsheet generation
Message-Id: <fruq7b$uds$1@ijustice.itsc.cuhk.edu.hk>


>    my %skipped;
>    $skipped{$_} = 1 for 2, 4, 6;
>
>    for my $r (qw/field r/) {
>        for my $i (1..10) {
>            $skipped{$i} and next;
>            printf '%8s ', "$r$i";
>        }
>        print "\n";
>    }

Oh! It seems you and ccc31807 are providing the exact solution! In my case 
then I would place something like name, age, ... in the qw. But I guess I'll 
modify your for my $i ... into a several "if" in order to differentiate the 
categories to display, e.g. personal info, diagnosis results, ...

Nevertheless, I also thank Jim's suggestion on using OO. 




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

Date: Fri, 21 Mar 2008 08:14:04 +0800
From: "Ela" <ela@yantai.org>
Subject: generic declaration of variables
Message-Id: <fruukg$j1$1@ijustice.itsc.cuhk.edu.hk>

I am declaring the following variables at the beginning:

@usage='cg.pl afile gfile ffile outname gensf genqcf genpf';
die "Usage: @usage\n" if $#ARGV < @usage;

my ($afile, $gfile, $ffile, $outname, $gensf, $genqcf, $genpf);

I have 2 more questions here, the first, instead of copying the @usage to 
the my(), how can I better write the codes to avoid typo and work? I will 
use exactly the same name indeed and don't know how many more I will add. I 
don't like config file because it usually makes program no longer work after 
a period of maintenance (config file gets lost etc).
The second question is, how to allow the user input the arguments without 
restricting them in a specific order? e.g. gfile ahead of afile...?
I find that some of the arguments are necessary, while some others, such as 
flags, may be optional. How can I write it in a better way to check whether 
all the necessary arguments are provided instead of fixing $#ARGV < @usage? 




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

Date: Thu, 20 Mar 2008 17:35:31 -0700 (PDT)
From: sandy_saydakov@yahoo.com
Subject: Re: generic declaration of variables
Message-Id: <07a3b010-df6e-4110-a1d5-50711d464c34@e10g2000prf.googlegroups.com>

On Mar 20, 5:14 pm, "Ela" <e...@yantai.org> wrote:
> I am declaring the following variables at the beginning:
>
> @usage='cg.pl afile gfile ffile outname gensf genqcf genpf';
> die "Usage: @usage\n" if $#ARGV < @usage;
>
> my ($afile, $gfile, $ffile, $outname, $gensf, $genqcf, $genpf);
>
> I have 2 more questions here, the first, instead of copying the @usage to
> the my(), how can I better write the codes to avoid typo and work? I will
> use exactly the same name indeed and don't know how many more I will add. I
> don't like config file because it usually makes program no longer work after
> a period of maintenance (config file gets lost etc).
> The second question is, how to allow the user input the arguments without
> restricting them in a specific order? e.g. gfile ahead of afile...?
> I find that some of the arguments are necessary, while some others, such as
> flags, may be optional. How can I write it in a better way to check whether
> all the necessary arguments are provided instead of fixing $#ARGV < @usage?

I would suggest using Getopt::Long  http://perldoc.perl.org/Getopt/Long.html

/sandy
http://myperlquiz.com/


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

Date: Thu, 20 Mar 2008 17:48:32 -0700 (PDT)
From: "benkasminbullock@gmail.com" <benkasminbullock@gmail.com>
Subject: Re: generic declaration of variables
Message-Id: <b5f58784-6b7f-461c-8e03-a789794a61ad@i12g2000prf.googlegroups.com>

On Mar 21, 9:14 am, "Ela" <e...@yantai.org> wrote:
> I am declaring the following variables at the beginning:
>
> @usage='cg.pl afile gfile ffile outname gensf genqcf genpf';
> die "Usage: @usage\n" if $#ARGV < @usage;
>
> my ($afile, $gfile, $ffile, $outname, $gensf, $genqcf, $genpf);
>
> I have 2 more questions here, the first, instead of copying the @usage to
> the my(), how can I better write the codes to avoid typo and work?

What I would do is to use a hash (here called %args) to store the
variables:

#! perl
use warnings;
use strict;
my @usage=qw/afile gfile ffile outname gensf genqcf genpf/;
die "Usage: cg.pl @usage\n" if @ARGV < @usage;
my %args;
@args{@usage} = @ARGV;
print join (" ", %args),"\n";

$ ./usage.pl a b c d e f
Usage: cg.pl afile gfile ffile outname gensf genqcf genpf

$ ./usage.pl a b c d e f g
genpf g genqcf f gensf e gfile b outname d ffile c afile a

> I will
> use exactly the same name indeed and don't know how many more I will add. I
> don't like config file because it usually makes program no longer work after
> a period of maintenance (config file gets lost etc).
> The second question is, how to allow the user input the arguments without
> restricting them in a specific order? e.g. gfile ahead of afile...?

It's not possible for me to answer that question without information
about how the program knows how to distinguish between gfile, afile,
etc.

> I find that some of the arguments are necessary, while some others, such as
> flags, may be optional. How can I write it in a better way to check whether
> all the necessary arguments are provided instead of fixing $#ARGV < @usage?

I'll leave that as an exercise for you to attempt yourself.


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

Date: Thu, 20 Mar 2008 15:55:57 -0800
From: "Robbie Hatley" <see.my.signature@for.my.email.address>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <JcydnX8pYqbrdn_anZ2dnUVZ_saknZ2d@giganews.com>

"Ben Bullock" wrote:

> On Wed, 19 Mar 2008 23:13:02 -0800, Robbie Hatley wrote:
>
> > my @Charset = map chr, 9, 32..126;
> > my @TempCharset = @Charset;
> > my @PermCharset;
> > while (@TempCharset > 0)
> > {
> >    my $RandomInt  = rand_int(0, @TempCharset - 1); my $RandomChar =
> >    $TempCharset[$RandomInt]; push @PermCharset, $RandomChar;
> >    delete $TempCharset[$RandomInt];
> > }
> > print @PermCharset, "\n";
> >
> > ... No wasted steps ...
>
> Bad news: there are rather a lot of wasted steps.
> If you add the statement
> use warnings;
> at the top of the above you might get a shock. You'll get several hundred
> warnings when
> print @PermCharset, "\n";
> is executed.
> The underlying reason why @PermCharset is messed up is that
> delete $TempCharset[$RandomInt];
> doesn't do what you think - it deletes the contents of @TempCharset at
> offset $RandomInt, but it doesn't move the remaining array entries to
> fill in the gap.
> splice (@TempCharset, $RandomInt, 1);
> is what you should have done.
> Remember: always "use warnings;".

Ewww, you're right.  I put "use strict" and "use warnings" in there,
along with an extra print statement, and I found that instead of
iterating 96 times (as I had presumed), that loop iterates 335 times!

I don't recall seeing the camel book mention that "delete" doesn't
close-up the gaps!  When I looked up "delete" and "splice" on
http://perldoc.perl.org/perlfunc.html
however, I got the gory details.  Thanks for the tip on "splice"!
That works much better.  The loop only runs 96 times (as it should),
and doesn't produce any warnings (because it's not trying to do
horrible stuff like access uninitialized RAM areas, as my old
version was).

New version:

#permute.perl
use strict;
use warnings;
sub rand_int
{
   my ($min, $max) = @_;
   return int ( $min + rand ( $max - $min + 0.999 ) ) ;
}
srand;
my @Charset = map chr, 9, 32..126;
my @TempCharset = @Charset;
my @PermCharset;
while (@TempCharset > 0)
{
   my $RandomInt  = rand_int(0, @TempCharset - 1);
   my $RandomChar = $TempCharset[$RandomInt];
   push @PermCharset, $RandomChar;
   splice @TempCharset, $RandomInt, 1;
}
print @PermCharset, "\n";

-- 
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant




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

Date: Thu, 20 Mar 2008 23:04:45 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <x7y78dxaib.fsf@mail.sysarch.com>

>>>>> "RH" == Robbie Hatley <see.my.signature@for.my.email.address> writes:

  RH> srand;

srand not needed anymore with modern perls

  RH> my @Charset = map chr, 9, 32..126;


  RH> my @TempCharset = @Charset;
  RH> my @PermCharset;


  RH> while (@TempCharset > 0)
  RH> {
  RH>    my $RandomInt  = rand_int(0, @TempCharset - 1);

that call to rand_int isn't needed. rand @TempCharset is all you
need. the index operation will do an implicit int() for you.

  RH>    my $RandomChar = $TempCharset[$RandomInt];
  RH>    push @PermCharset, $RandomChar;
  RH>    splice @TempCharset, $RandomInt, 1;

all four of those lines can be reduced to 1!

	push @PermCharset, splice( @TempCharset, rand @TempCharset, 1 ) ;

note that splice returns what you splice out so the index line and
$randomchar aren't needed. and the random int is a short expression so
it doesn't need a temp var too.

and now you can even make it all one statement with a modifier!

	push @PermCharset, splice( @TempCharset, rand @TempCharset, 1 )
		while @TempCharset ;

no randint sub, no temp vars, no block.
perl is so neat like that!

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Thu, 20 Mar 2008 14:01:00 -0700 (PDT)
From: Vinay Nagrik <jainarunk@gmail.com>
Subject: Re: Strange syntex: beginner
Message-Id: <832b5796-fa79-4a54-87bd-ba9d5df9efbc@h11g2000prf.googlegroups.com>

On Mar 20, 9:18=A0am, Tony Curtis <tony_curti...@yahoo.com> wrote:
> ccc31807 wrote:
> > On Mar 20, 12:07 pm, Nagrik <vnag...@gmail.com> wrote:
> >> Hello Group,
>
> >> I am new to learning Perl and am struggling with a syntex encountered
> >> in the code. =A0It looks like
>
> >> < a.txt b.pl > signature
>
> >> My question is
>
> >> what does the first character (<) mean.
>
> >> What b.pl is doing with a.txt.
>
> >> I guess the output of the program goes to signature.
>
> >> BTW: The line I mentioned was in a bash script file.
>
> >> Can someone help.
>
> >> Thanks.
>
> >> nagrik
>
> > < and > are redirection operators. The line you quote can be
> > translated as follows:
>
> > Get the input (<) from the file named 'a.txt', run the script named
> > 'b.pl', and write the output (>) to the file named 'signature'.
>
> but that's not perl, BTW
>
> hth
> t- Hide quoted text -
>
> - Show quoted text -

As I said earlier this line was written in a bash script, and looks
like reading a file inside a perl script and then outputing it.

nagrik


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

Date: Thu, 20 Mar 2008 18:43:01 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Strange syntex: beginner
Message-Id: <47e2f685$0$87064$815e3792@news.qwest.net>

Vinay Nagrik wrote:
> On Mar 20, 9:18 am, Tony Curtis <tony_curti...@yahoo.com> wrote:
>> ccc31807 wrote:
>>> On Mar 20, 12:07 pm, Nagrik <vnag...@gmail.com> wrote:
>>>> Hello Group,
>>>> I am new to learning Perl and am struggling with a syntex encountered
>>>> in the code.  It looks like
>>>> < a.txt b.pl > signature
>>>> My question is
>>>> what does the first character (<) mean.
>>>> What b.pl is doing with a.txt.
>>>> I guess the output of the program goes to signature.
>>>> BTW: The line I mentioned was in a bash script file.
>>>> Can someone help.
>>>> Thanks.
>>>> nagrik
>>> < and > are redirection operators. The line you quote can be
>>> translated as follows:
>>> Get the input (<) from the file named 'a.txt', run the script named
>>> 'b.pl', and write the output (>) to the file named 'signature'.
>> but that's not perl, BTW
>>
>> hth

> As I said earlier this line was written in a bash script, and looks
> like reading a file inside a perl script and then outputing it.

As Tony said earlier, "that's not perl".  Or more bluntly, the
redirection operators in a bash script have nothing at all to
do with perl, so why are you asking in this newsgroup?

Ask what it does in a bash newsgroup or experiment with it on your
own.  Hint: run it with a made up file name, instead of one that
exists.

< dummy b.pl > signature


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

Date: Thu, 20 Mar 2008 20:29:52 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Strange syntex: beginner
Message-Id: <slrnfu63sg.1o3.tadmc@tadmc30.sbcglobal.net>

Vinay Nagrik <jainarunk@gmail.com> wrote:
> On Mar 20, 9:18 am, Tony Curtis <tony_curti...@yahoo.com> wrote:
>> ccc31807 wrote:
>> > On Mar 20, 12:07 pm, Nagrik <vnag...@gmail.com> wrote:


>> >> I am new to learning Perl and am struggling with a syntex encountered
>> >> in the code.  


But the syntax you have encountered is not Perl syntax.


>> >>It looks like
>>
>> >> < a.txt b.pl > signature


>> >> BTW: The line I mentioned was in a bash script file.


The syntax that you have a question about is bash syntax.


>> but that's not perl, BTW

> As I said earlier this line was written in a bash script, 


So pointing out that it is not Perl is accurate.

Yes?

Please ask Perl questions in a Perl newsgroup and shell questions
in a shell newsgroup.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 20 Mar 2008 20:13:35 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: strategies other than subroutine and OO?
Message-Id: <slrnfu62tv.1o3.tadmc@tadmc30.sbcglobal.net>

Ela <ela@yantai.org> wrote:
>> Maybe you can take the lines that are exactly duplicated and put those
>> into sub functions.  If you define the sub functions inside the main
>> function they can access the main function's 'my' variables, so you
>> don't need to pass them as arguments.
>>
>
> From perlintro:
> A Perl script or program consists of one or more statements. These 
> statements are simply written in the script in a straightforward fashion. 
> There is no need to have a main() function or anything of that kind.


The main referred to in perlintro is not the main in Ela's followup.

The main function that perlintro mentions is a concept 
common is several other programming languages.

Ela's main function is referring to the "parent" or "outer" functions,
that is, it is a colloquial use of the word "main" rather than a
technical use.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: 20 Mar 2008 18:20:52 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <Xns9A677D9C057A4castleamber@130.133.1.4>

RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote:

> In nearly 30 years of programming I have completely avoided use of
> GOTO in a professional context. All I have seen continues to convince
> me that Dijkstra was right on this matter. YMMV.

So you avoid last, next, etc. and returns in the middle of subs as well?
To me those are all forms of GOTO.

-- 
John

http://johnbokma.com/


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

Date: 20 Mar 2008 18:26:43 GMT
From: xhoster@gmail.com
Subject: Re: strategys other than subroutine and OO?
Message-Id: <20080320142644.948$sS@newsreader.com>

John Bokma <john@castleamber.com> wrote:
> RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote:
>
> > In nearly 30 years of programming I have completely avoided use of
> > GOTO in a professional context. All I have seen continues to convince
> > me that Dijkstra was right on this matter. YMMV.
>
> So you avoid last, next, etc. and returns in the middle of subs as well?
> To me those are all forms of GOTO.

Where do you draw the line?  All looping and branching are also forms of
GOTO, if that is the way one wants to look at it.

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: Thu, 20 Mar 2008 19:38:12 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <64fp8mF2bmnjaU3@mid.individual.net>

RedGrittyBrick wrote:
> Abigail wrote:
>>
>>What Knuth and Dijkstra are saying is that it's not so much the use of
>>"goto" that should be avoided, the real horror is unstructured programming.
>>But most people only know the title of Dijkstra's paper, and not the
>>content [1], let alone know what others have to say about it.
> 
> Guilty as charged. Perhaps I am unlucky in that almost all the examples 
> of GOTO I have had to wrestle with, have been in examples of "spaghetti 
> programming". It is certainly possible to write spaghetti code without 
> using GOTO, but use of GOTO seems to encourage this trend in many 
> programmers.

Who the hell uses goto today???

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: 20 Mar 2008 19:05:49 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <Xns9A67853AE6835castleamber@130.133.1.4>

xhoster@gmail.com wrote:

> John Bokma <john@castleamber.com> wrote:
>> RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote:
>>
>> > In nearly 30 years of programming I have completely avoided use of
>> > GOTO in a professional context. All I have seen continues to convince
>> > me that Dijkstra was right on this matter. YMMV.
>>
>> So you avoid last, next, etc. and returns in the middle of subs as 
well?
>> To me those are all forms of GOTO.
> 
> Where do you draw the line?

That's a good summary.

-- 
John

http://johnbokma.com/


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

Date: Thu, 20 Mar 2008 12:36:03 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <b346e720-50f3-4db2-9a8c-129d35f1a589@b64g2000hsa.googlegroups.com>

On Mar 20, 2:26 pm, xhos...@gmail.com wrote:
> > So you avoid last, next, etc. and returns in the middle of subs as well?
> > To me those are all forms of GOTO.
>
> Where do you draw the line?  All looping and branching are also forms of
> GOTO, if that is the way one wants to look at it.

If you want to ~look~ at it, you can draw flow charts and make sure
that each structure, sequential, looping, or selection, has only one
entry point and one exit point. Alternatively, you can construct a
control flow graph and make sure each structure has one start and one
end node.

All the next, last, redo, and return statements do is exit a loop
according to the value of a variable. True, they are forms of a goto
instruction, but I think we have the idea that goto implies goint to
any arbitrary point in a program while the next, etc., just break out
of the inmost loop (except for labeled loops, but even then they don't
transfer control arbitrarily.)

I think that the point is writing clear, concise, and even beautiful
code, avoiding excessive subjectivism and ideosyncratic expressions,
and following consistent stylistic conventions. This will never go out
of style.

I expect that in about twenty years, someone will write an article
that Java will be considered harmful. This won't be the fault of Java,
but of the habit of forcing all code to conform to OO conventions.
This won't be Java's fault, but the fault of all those who conform
excessively to the One True Way, and discover much later that it's
just another way.

CC


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

Date: Thu, 20 Mar 2008 19:58:04 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <c7sab5-jnf.ln1@osiris.mauzo.dyndns.org>


Quoth Frank Seitz <devnull4711@web.de>:
> 
> Who the hell uses goto today???

Depends on the language. While I have never used goto in Perl, it is
common in C to see a function structured like the one below: see, for
instance, much of the perl source. This is a consequence of having to
de-allocate everything manually in C. Of course, one has to be careful:
it is all to easy for such a function to degenerate into an
incomprehensible mess.

Ben

    int
    do_something(...)
    {
        Foo *foo;
        Bar *bar;
        int rv;

        foo = allocate_Foo();
        if (!foo) {
            rv = ENOFOO;
            goto out;
        }

        bar = allocate_Bar();
        if (!bar) {
            rv = ENOBAR;
            goto out_foo;
        }

        rv = try_something(foo, bar);
        if (rv < 0)
            goto out_bar;

        do_something_else();

    out_bar:
        free_Bar(bar);

    out_foo:
        free_Foo(foo);

    out:
        return rv;
    }


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

Date: 20 Mar 2008 22:21:34 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: strategys other than subroutine and OO?
Message-Id: <slrnfu5ore.n25.abigail@alexandra.abigail.be>

                                          _
Frank Seitz (devnull4711@web.de) wrote on VCCCXV September MCMXCIII in
<URL:news:64fp8mF2bmnjaU3@mid.individual.net>:
][  RedGrittyBrick wrote:
][ > Abigail wrote:
][ >>
][ >>What Knuth and Dijkstra are saying is that it's not so much the use of
][ >>"goto" that should be avoided, the real horror is unstructured programming.
][ >>But most people only know the title of Dijkstra's paper, and not the
][ >>content [1], let alone know what others have to say about it.
][ > 
][ > Guilty as charged. Perhaps I am unlucky in that almost all the examples 
][ > of GOTO I have had to wrestle with, have been in examples of "spaghetti 
][ > programming". It is certainly possible to write spaghetti code without 
][ > using GOTO, but use of GOTO seems to encourage this trend in many 
][ > programmers.
][  
][  Who the hell uses goto today???


I do. Not often, but there are constructs I use less.


Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


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

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


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