zentara has asked for the wisdom of the Perl Monks concerning the following question:

I like to try and break my codelines into lengths long enough so I don't have to scroll horizontally. In most Perl situations, it's easy enough, just break the code statements into nice sets of short lines. However, I occaisionally run into a situation where this isn't possible. For instance:

In a Tk program, I'm sending some text to a label. The long statement might be something like: (The following is all one line, the pre tags are on purpose :-) ).

$game{'board'}{'stat'} = "$playerin submits $game{'board'}{'proposedwo +rduser'} $game{'board'}{'proposedscore'} points";
Now if I break this, the hidden newlines will be picked up by the Tk::Label widget, which I don't want.

So is it possible to put some kind of slash at the break points to indicate to ignore the newline? It really isn't a major problem for me, I was just wondering if there is a method which dosn't involve too much extra work.


I'm not really a human, but I play one on earth. flash japh

Edit by tye, replace PRE with CODE

Replies are listed 'Best First'.
Re: breaking long code lines
by Aristotle (Chancellor) on Jul 28, 2004 at 21:36 UTC
    Why do you need to?
    $game{'board'}{'stat'} = "$playerin submits" . " $game{'board'}{'proposedworduser'}" . " $game{'board'}{'proposedscore'} points"; # or $game{'board'}{'stat'} = join( " ", $playerin, "submits", $game{'board'}{'proposedworduser'}, " ", $game{'board'}{'proposedscore'} "points" ); # or $game{'board'}{'stat'} = sprintf( "%s submits %s %s points", $playerin, $game{'board'}{'proposedworduser'}, $game{'board'}{'proposedscore'} );
    TMTOWTDI, as always.

    Makeshifts last the longest.

Re: breaking long code lines
by grinder (Bishop) on Jul 28, 2004 at 22:15 UTC

    Two things come to mind: you don't need the apostrophes, $game{board}{proposedworduser} will interpolate just fine. Another thing is that with a temporary variable, you can factor out the $game{'board'} derefs.

    my $g = $game{'board'}; $g{stat} = "$playerin submits $g{proposedworduser} $g{proposedscore} p +oints";

    Now, if those hash keys weren't so long, you'd be in business :)


    update: that should probably read  $g->{stat}, but you knew that already...

    - another intruder with the mooring of the heat of the Perl

Re: breaking long code lines
by davido (Cardinal) on Jul 28, 2004 at 23:22 UTC
    my $string = "If the lines are too long you can always " . "use the concatenation operator to build " . "smaller strings into one large one.\n"; print $string;

    Dave

Re: breaking long code lines
by itub (Priest) on Jul 28, 2004 at 21:40 UTC
    $long_string = "dfjak;jafdkslja;sfdjklasdfjkladfsjk" . "dfasjkl;dsafjlkrewnmjvcxkludsfak;lj32;jtw4lk" . "dfasjufdsa98fn8j09jfdsa09j 8 a89j908adfjfdad";
Re: breaking long code lines
by CountZero (Bishop) on Jul 28, 2004 at 21:36 UTC
    That's not really a Perl-issue, but more of a Tk-issue.

    More generally, I think it mostly depends on the editor you are using. Some editors allow indeed for "line continuation codes" or do the word-wrap thing automatically. KOMODO comes to mind in this respect.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law