in reply to Re: Concatnate long statement
in thread Concatnate long statement

so we dont need any special operator? like in vb we use the & for long sql statement. Thank

Replies are listed 'Best First'.
Re^3: Concatnate long statement
by ikegami (Patriarch) on Jul 03, 2007 at 21:57 UTC

    You are confusing two concepts.

    To concatenate strings is to combine two strings into one. The string concatenation operator is & in VB and . in Perl.

    VB: var1 = "abc" & var2 Perl (Concatenation): $var1 = 'abc' . $var2 Perl (Interpolation): $var1 = "abc$var2"; Perl (Concatenation using join): $var1 = join('', 'abc', $var2);

    In VB, all statements must be on the same line. The _ operator allows you to break a statement into multiple lines. This has nothing to do with string concatenation. Perl doesn't require a continuation operator. Instead, one must tell Perl where the statement ends using ;.

    VB: var = func(var1, var2, var3) Perl: $var = func($var1, $var2, $var3); VB: var = func( _ var1, _ var2, _ var3 _ ) Perl: $var = func( $var1, $var2, $var3 );

    Together:

    VB: stmt = "SELECT *" & _ " FROM table" & _ " ORDER BY field" Perl: $stmt = "SELECT *" . " FROM table" . " ORDER BY field" Perl (Since SQL servers treats newlines as whitespace): $stmt = " SELECT * FROM table ORDER BY field ";
Re^3: Concatnate long statement
by aufflick (Deacon) on Jul 04, 2007 at 06:16 UTC
    Welcome to PerlMonks - I think you will find your life more enjoyable here than with VB :)

    Certainly free form code is much nicer. For instance you can use the string concatenation or newline examples given in other answers for tidying up your code in Socket Problem.

Re^3: Concatnate long statement
by leocharre (Priest) on Jul 04, 2007 at 13:07 UTC
    The following example has a statement per line.
    #!/usr/bin/perl -w use strict; use warnings; use Time::Format 'time_format'; printf "Hello world, today is %s\n", time_format('mm dd yyyy',time); exit;
    The following example has statements broken up into lines and is still valid:
    #!/usr/bin/perl -w use strict; use warnings; use Time::Format 'time_format'; printf "Hello world, today is %s\n", time_format( 'mm dd yyyy', time ); exit;
    The following example is still valid but has unnacceptable formatting for human beings:
    #!/usr/bin/perl -w use strict; use warnings; use Time::Format 'time_format'; printf "Hello world, today is %s\n", time_format( 'mm dd yyyy', time) ; exit ;
    The following example breaks:
    #!/usr/bin/perl -w use strict; use warnings; use Time::Format 'time_format' printf "Hello world, today is %s\n", time_format('mm dd yyyy',time); exit;
    Personally I use vim, set expandtab, and I break a long statement with new line and tab. If you foresee coding perl regularly, you need a copy of Perl Best Practices by Damian Conway.