Long line in perl script

Discussion in 'Perl Misc' started by Subra, Feb 22, 2008.

  1. Subra

    Subra Guest

    Hi ,

    I have very long line in perl script. I need to break it into
    multiple lines. Some thing like below.

    Present Code :-

    if ($settings->{$service_name}-
    >{'pin_home_dir'} || $settings->{$service_type}->{'pin_home_dir'}) {


    New code should be:
    if ($settings-
    >{$service_name}->{'pin_home_dir'} ||


    $settings->{$service_type}->{'pin_home_dir'}) {


    Is there any special character like in C (\) which I should put at the
    end of the broken line ????

    As this script is suppose to run in many platforms so this info is
    very imp for me.

    thanks,
    Subra...
     
    Subra, Feb 22, 2008
    #1
    1. Advertising

  2. Subra wrote:
    > I have very long line in perl script. I need to break it into
    > multiple lines. Some thing like below.
    >
    > Present Code :-
    >
    > if ($settings->{$service_name}-
    >> {'pin_home_dir'} || $settings->{$service_type}->{'pin_home_dir'}) {

    >
    > New code should be:
    > if ($settings-
    >> {$service_name}->{'pin_home_dir'} ||

    >
    > $settings->{$service_type}->{'pin_home_dir'}) {


    Looks weird to me. How about:

    if (
    $settings->{$service_name}->{'pin_home_dir'}
    ||
    $settings->{$service_type}->{'pin_home_dir'}
    ) {

    > Is there any special character like in C (\) which I should put at the
    > end of the broken line ????


    No.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 22, 2008
    #2
    1. Advertising

  3. Subra

    rthangam Guest

    On Feb 22, 2:18 pm, Gunnar Hjalmarsson <> wrote:
    > Subra wrote:
    > > I have very long line in perl script. I need to break it into
    > > multiple lines. Some thing like below.

    >
    > > Present Code :-

    >
    > > if ($settings->{$service_name}-
    > >> {'pin_home_dir'} || $settings->{$service_type}->{'pin_home_dir'}) {

    >
    > > New code should be:
    > > if ($settings-
    > >> {$service_name}->{'pin_home_dir'} ||

    >
    > > $settings->{$service_type}->{'pin_home_dir'}) {

    >
    > Looks weird to me. How about:
    >
    > if (
    > $settings->{$service_name}->{'pin_home_dir'}
    > ||
    > $settings->{$service_type}->{'pin_home_dir'}
    > ) {
    >
    > > Is there any special character like in C (\) which I should put at the
    > > end of the broken line ????

    >
    > No.
    >
    > --
    > Gunnar Hjalmarsson
    > Email:http://www.gunnar.cc/cgi-bin/contact.pl


    Did you using perl beautify ?
     
    rthangam, Feb 22, 2008
    #3
  4. rthangam wrote:
    > On Feb 22, 2:18 pm, Gunnar Hjalmarsson <> wrote:
    >> Looks weird to me. How about:
    >>
    >> if (
    >> $settings->{$service_name}->{'pin_home_dir'}
    >> ||
    >> $settings->{$service_type}->{'pin_home_dir'}
    >> ) {

    >
    > Did you using perl beautify ?


    What's that? Anyway, I didn't use any such thing.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 22, 2008
    #4
  5. Subra

    ccc31807 Guest

    On Feb 22, 3:17 am, Subra <> wrote:
    > Hi ,
    >
    > I have very long line in perl script. I need to break it into
    > multiple lines. Some thing like below.
    >
    > Present Code :-
    >
    > if ($settings->{$service_name}-
    >
    > >{'pin_home_dir'} || $settings->{$service_type}->{'pin_home_dir'}) {

    >
    > New code should be:
    > if ($settings-
    >
    > >{$service_name}->{'pin_home_dir'} ||

    >
    > $settings->{$service_type}->{'pin_home_dir'}) {


    my ($test1, $test2);
    $test1 = $settings->{$service_name}->{'pin_home_dir'};
    $test2 = $settings->{$service_type}->{'pin_home_dir'};
    if ($test1 or $test2)
    {
    #your code here
    }

    CC
     
    ccc31807, Feb 22, 2008
    #5
  6. On Feb 22, 2:43 am, Gunnar Hjalmarsson <> wrote:
    > rthangam wrote:
    > > On Feb 22, 2:18 pm, Gunnar Hjalmarsson <> wrote:
    > >> Looks weird to me. How about:

    >
    > >> if (
    > >> $settings->{$service_name}->{'pin_home_dir'}
    > >> ||
    > >> $settings->{$service_type}->{'pin_home_dir'}
    > >> ) {

    >
    > > Did you using perl beautify ?

    >
    > What's that? Anyway, I didn't use any such thing.
    >


    s/perl beautify/perltidy/ perhaps ... ?

    eg, perltidy output:

    if ( $settings->{$service_name}->{'pin_home_dir'}
    || $settings->{$service_type}->{'pin_home_dir'} )
    {

    --
    Charles DeRykus
     
    comp.llang.perl.moderated, Feb 22, 2008
    #6
  7. "Petr Vileta" <> wrote:
    >Subra wrote:
    >You can wrap line at any space in your long line. Example:


    That is true. And even more than that: you can even place a line break
    everywhere where you _could_ place a space, because Perl is a free format
    language and all white spaces are treated the same.

    jue
     
    Jürgen Exner, Feb 23, 2008
    #7
  8. Petr Vileta wrote:
    >
    > Subra wrote:
    >>
    >> Is there any special character like in C (\) which I should put at the
    >> end of the broken line ????
    >>

    > You can wrap line at any space in your long line. Example:
    >
    > if ($settings->{$service_name}->{'pin_home_dir'} ||
    > $settings->{$service_type}->{'pin_home_dir'}) {


    It doesn't even have to be at a space:

    $ perl -MData::Dumper -le'$w->{x}->{y}->{z} = "hello"; print Dumper $w'
    $VAR1 = {
    'x' => {
    'y' => {
    'z' => 'hello'
    }
    }
    };

    $ perl -MData::Dumper -le'
    $w
    ->
    {x}
    ->
    {y}
    ->
    {z}
    =
    "hello";
    print Dumper $w'
    $VAR1 = {
    'x' => {
    'y' => {
    'z' => 'hello'
    }
    }
    };


    John
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
     
    John W. Krahn, Feb 23, 2008
    #8
  9. Subra

    Subra Guest

    On Feb 23, 7:16 pm, "Petr Vileta" <> wrote:
    > John W. Krahn wrote:
    > > Petr Vileta wrote:

    >
    > >> Subra wrote:

    >
    > >>> Is there any special character like in C (\) which I should put at
    > >>> the end of the broken line ????

    >
    > >> You can wrap line at any space in your long line. Example:

    >
    > >> if ($settings->{$service_name}->{'pin_home_dir'} ||
    > >> $settings->{$service_type}->{'pin_home_dir'}) {

    >
    > > It doesn't even have to be at a space:

    >
    > > $ perl -MData::Dumper -le'$w->{x}->{y}->{z} = "hello"; print Dumper
    > > $w' $VAR1 = {
    > > 'x' => {
    > > 'y' => {
    > > 'z' => 'hello'
    > > }
    > > }
    > > };

    >
    > > $ perl -MData::Dumper -le'
    > > $w
    > > ->
    > > {x}
    > > ->
    > > {y}
    > > ->
    > > {z}
    > > =
    > > "hello";
    > > print Dumper $w'
    > > $VAR1 = {
    > > 'x' => {
    > > 'y' => {
    > > 'z' => 'hello'
    > > }
    > > }
    > > };

    >
    > Yes, of course, but wrapping line at space (or tab) is better readable for
    > human and for perl novice too ;-)
    > --
    > Petr Vileta, Czech republic
    > (My server rejects all messages from Yahoo and Hotmail. Send me your
    > mail from another non-spammer site please.)
    >
    > Please reply to <petr AT practisoft DOT cz>


    Thanks one and all for making it clear....
     
    Subra, Feb 25, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    707
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,220
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    496
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    830
    Peter Nilsson
    Jan 15, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,844
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page