unless <--) )[ not $counter ]; -- Steve [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <20031021195420.GE10120@grazzini.net> [ref] => <20031021185758.GC10120@grazzini.net> <20031021200644.53633.qmail@web41103.mail.yahoo.com> [htmlstate] => on_nl2br [postusername] => Steve Grazzini [ip] => grazz@pobox.com [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> unless <--) )[ not $counter ];[/quote] ??? :-| -- Kevin Pfeiffer [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <21772991.OkKeCmJCK6@sputnik.tiros.net> [ref] => <20031021185758.GC10120@grazzini.net> <20031021200644.53633.qmail@web41103.mail.yahoo.com> <20031021195420.GE10120@grazzini.net> [htmlstate] => on_nl2br [postusername] => Kevin Pfeiffer [ip] => pfeiffer@iu-bre [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> unless <--) )[ not $counter ];[/quote] > >??? :-| >[/quote] I think the author was trying to be cute... I got a chuckle out of it! print +( qw(second first --> unless <--) )[ not $counter ]; Basically, you are creating an anonymous (right term?) array, and printing the "not $counter"'th element. So if $counter is 0, you print "first", otherwise you print "second". The other stuff in the array is there just to satisfy the "buried" unless requested by the OP. However, as you see here, it does not use the keyword "unless", just a string "unless". The only elements that will ever be accessed are "second" and "first"... It could also be written as: print +( qw(second first) )[ not $counter ]; HTH Alan [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <0AACDA3B85278749AECEF93D75324A667533A7@ares.loislaw.com> [ref] => [htmlstate] => on_nl2br [postusername] => Alan Perry [ip] => aperry@loislaw. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 6 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Trivial 'unless' Question - PERL Beginners
Professional Web Applications Themes

Trivial 'unless' Question - PERL Beginners

On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote: > # ... but can I do something like.... > print "first\n" unless ($counter) else { print "second\n"; Not really. You could use the conditional operator, though. print $counter ? "second\n" : "first\n"; -- Steve...

  1. #1

    Default Re: Trivial 'unless' Question

    On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
    > # ... but can I do something like....
    > print "first\n" unless ($counter) else { print "second\n";
    Not really. You could use the conditional operator, though.

    print $counter ? "second\n" : "first\n";

    --
    Steve
    Steve Grazzini Guest

  2. #2

    Default Trivial 'unless' Question

    Hi ..... very trivial ... is there a way or correct syntax to add an 'if' tp
    the following 'unless' statement?

    # this works fine ...
    print "first\n" unless ($counter);
    # ... but can I do something like....
    print "first\n" unless ($counter) else { print "second\n";
    # (syntax error)

    I know I can do this:

    #!/usr/bin/perl
    use warnings;
    use strict;
    my $counter = 0;

    unless ($counter) {
    print "first\n";
    } else {
    print "second\n";
    }

    ..... but I wanted to put the 'unless' later in the statement. I couldn't
    find anything in the FAQ or perldoc on this one.

    TIA!

    -JW




    __________________________________
    Do you Yahoo!?
    The New Yahoo! Shopping - with improved product search
    [url]http://shopping.[/url]
    Jeff Westman Guest

  3. #3

    Default Re: Trivial 'unless' Question

    On Tue, Oct 21, 2003 at 01:06:44PM -0700, Jeff Westman wrote:
    > Steve Grazzini <grazzpobox.com> wrote:
    > > On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
    > > > # ... but can I do something like....
    > > > print "first\n" unless ($counter) else { print "second\n";
    > >
    > > Not really. You could use the conditional operator, though.
    > >
    > > print $counter ? "second\n" : "first\n";
    >
    > True, but I was looking for a way to do this with a somewhat "buried"
    > unless keyword.
    print +( qw(second first --> unless <--) )[ not $counter ];

    --
    Steve
    Steve Grazzini Guest

  4. #4

    Default Re: Trivial 'unless' Question

    Steve Grazzini <grazzpobox.com> wrote:
    > On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
    > > # ... but can I do something like....
    > > print "first\n" unless ($counter) else { print "second\n";
    >
    > Not really. You could use the conditional operator, though.
    >
    > print $counter ? "second\n" : "first\n";
    True, but I was looking for a way to do this with a somewhat "buried" unless
    keyword.

    TA

    -JW

    __________________________________
    Do you Yahoo!?
    The New Yahoo! Shopping - with improved product search
    [url]http://shopping.[/url]
    Jeff Westman Guest

  5. #5

    Default Re: Trivial 'unless' Question

    In article <20031021195420.GE10120grazzini.net>, Steve Grazzini wrote:
    > On Tue, Oct 21, 2003 at 01:06:44PM -0700, Jeff Westman wrote:
    >> Steve Grazzini <grazzpobox.com> wrote:
    >> > On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
    >> > > # ... but can I do something like....
    >> > > print "first\n" unless ($counter) else { print "second\n";
    >> >
    >> > Not really. You could use the conditional operator, though.
    >> >
    >> > print $counter ? "second\n" : "first\n";
    >>
    >> True, but I was looking for a way to do this with a somewhat "buried"
    >> unless keyword.
    >
    > print +( qw(second first --> unless <--) )[ not $counter ];
    ??? :-|


    --
    Kevin Pfeiffer

    Kevin Pfeiffer Guest

  6. #6

    Default RE: Trivial 'unless' Question

    On Tuesday, October 21, 2003 16:01, Kevin Pfeiffer wrote:
    >In article <20031021195420.GE10120grazzini.net>, Steve Grazzini wrote:
    >
    >> On Tue, Oct 21, 2003 at 01:06:44PM -0700, Jeff Westman wrote:
    >>> Steve Grazzini <grazzpobox.com> wrote:
    >>> > On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
    >>> > > # ... but can I do something like....
    >>> > > print "first\n" unless ($counter) else { print "second\n";
    >>> >
    >>> > Not really. You could use the conditional operator, though.
    >>> >
    >>> > print $counter ? "second\n" : "first\n";
    >>>
    >>> True, but I was looking for a way to do this with a somewhat "buried"
    >>> unless keyword.
    >>
    >> print +( qw(second first --> unless <--) )[ not $counter ];
    >
    >??? :-|
    >
    I think the author was trying to be cute... I got a chuckle out of it!

    print +( qw(second first --> unless <--) )[ not $counter ];

    Basically, you are creating an anonymous (right term?) array, and printing
    the "not $counter"'th element. So if $counter is 0, you print "first",
    otherwise you print "second". The other stuff in the array is there just to
    satisfy the "buried" unless requested by the OP. However, as you see here,
    it does not use the keyword "unless", just a string "unless". The only
    elements that will ever be accessed are "second" and "first"...

    It could also be written as:

    print +( qw(second first) )[ not $counter ];

    HTH
    Alan
    Alan Perry Guest

  7. #7

    Default Re: Trivial 'unless' Question

    [email]westfour[/email] (Jeff Westman) wrote in message news:<20031021191717.66026.qmailweb41107.mail.yah oo.com>...
    > # ... but can I do something like....
    > print "first\n" unless ($counter) else { print "second\n";
    The predicate conditionals are limited: there is no elsing with them.
    The suggestion to use the ternary operator (?:) is appropriate for
    this example. If you really wanted to sneak some more conditional
    logic into a predicate, you'll have to do it with operators:
    print "first\n" unless ($counter and print "second\n");

    I strongly advise against that sort of garbling. It would be much
    clearer to write
    print(($counter) ? 'second'
    : 'first'
    , "\n");
    or just
    if ($counter == 0) { print "first\n" }
    else { print "second\n" }
    Roy Johnson Guest

Similar Threads

  1. a trivial type question
    By Eric Otto in forum Adobe Indesign Macintosh
    Replies: 1
    Last Post: October 5th, 07:58 PM
  2. Trivial encryption
    By Dave Anderson in forum ASP
    Replies: 8
    Last Post: August 18th, 11:53 PM
  3. Trivial stuff
    By The Magician in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: August 12th, 07:21 PM
  4. Trivial sqlplus questions
    By Sybrand Bakker in forum Oracle Server
    Replies: 0
    Last Post: December 21st, 11:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139