Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: raffle_tickets_generator

by Anonymous Monk
on Dec 03, 2015 at 11:19 UTC ( [id://1149291]=note: print w/replies, xml ) Need Help??


in reply to raffle_tickets_generator

Criticism invited, so here goes.

  • I'd write the long text strings as here-docs, or better yet, put them in __DATA__ section at the end.
    Paragraph mode perhaps to cut it up.
    my ($header, $body, $footer) = do { local $/ = ""; <DATA> };
  • I fail to see the reason to put $find through quotemeta. (And there's also the \Q\E).
  • It is advisable to use named constants instead of magic numbers: use constant COLS => 7;
  • For loop more concisely written using repetition operator: print $tombolatex $body x (1 + $N / COLS);
  • ...
  • All in all, it looks like a simple templating job.

Replies are listed 'Best First'.
Re^2: raffle_tickets_generator
by QuillMeantTen (Friar) on Dec 03, 2015 at 11:57 UTC

    It is the first time I hear about the DATA section, thanks for pointing this feature out! also that way to write loops is great, I'm going to correct that at once.

      Good reference that talks about paragraph mode.

      use strict; use warnings; my ($first,$second,$third); { local $/ = ''; ($first, $second, $third) = <DATA>; } printf "First: %s", $first; printf "Second: %s", $second; printf "Third: %s", $third; __DATA__ this will go into the variable called first second here tail end charlie
      Dum Spiro Spero

        Just to be sure I get it, when you localise $/ as '' perl will see an empty line as the record separator? even if said empty line is actually just one '\n' character.

        I understand that making $/ equal '\n' you would have ended up with

        $first = "this will"; $second="go into the variable"; $third = "called first";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2024-04-24 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found