- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Simple perl question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:25 AM
06-22-2004 01:25 AM
When using the "next if" loop in perl, what is the correct syntax for :-
next if ($x ne "some string")
Jeff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:29 AM
06-22-2004 01:29 AM
Re: Simple perl question
next some boolean operation;
or
next;
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:30 AM
06-22-2004 01:30 AM
Re: Simple perl question
$x eq "some string" or next;
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:37 AM
06-22-2004 01:37 AM
Re: Simple perl question
print "hello" if $x > 5;
"unless" is also a modifier-
print "hello" unless $x <= 5;
In your example, the parenthesis aren't required, and using the "unless" modifier you get-
next unless $x eq "some string";
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:45 AM
06-22-2004 01:45 AM
Re: Simple perl question
Thanks for the replies. This is the full problem (I wish to print all the values of $last_field except the ones containing the string).
$last_field=pop(@array);
next unless ($last_field eq "some_string");
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:50 AM
06-22-2004 01:50 AM
Re: Simple perl question
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:55 AM
06-22-2004 01:55 AM
Re: Simple perl question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 01:58 AM
06-22-2004 01:58 AM
Re: Simple perl question
some loop:
printf(OUTPUTFILEPTR "%s",$last_field) unless ($last_field eq "some_string");
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 02:02 AM
06-22-2004 02:02 AM
Re: Simple perl question
I think it may be the fact I used the pop function on an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 02:29 AM
06-22-2004 02:29 AM
Solution#!/usr/bin/perl
#
@arrSTUFF="";
while (
push @arrSTUFF,$_;
}
foreach $last_field (@arrSTUFF) {
printf("%s\n",$last_field) unless ($last_field =~ "crazyman");
}
You can use "chomp" to remove "CR's" after the foreach line above:
chomp($last_field);
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 02:56 AM
06-22-2004 02:56 AM
Re: Simple perl question
Knowing that, the initialization isn't needed at all, and the chomp can be done in one go
=~ operator doesn't take " as delimiter without the m prefix
For automatically aliasses $_, and printf isn't needed for a single string. The added \n (newline can be shorthanded to the -l command line opting, reducing Harry's snippet to the syntacticcally valid:
#!/usr/bin/perl -wl
chomp (my @arr =
for (@arr) {
print unless /crazyman/;
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 05:02 AM
06-22-2004 05:02 AM
Re: Simple perl question
want in one step:
@array2 = grep(/^some_string$/, @array);
The array @array2 will be the subset of
items from @array that are not "some_string".
The ^ and $ anchor the pattern so that you
match "some_string" exactly and do not match
"also_some_string" or "some_string_or_other".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2004 07:47 AM
06-23-2004 07:47 AM
Re: Simple perl question
To trap for division by zero:
@a(0 .. 20)
@b(-10 .. 10)
DIVISION: while(@a){
$a=pop @a;
$b=pop @b;
next DIVISION if ($b == 0);
print "$a / $b = ".$a/$b."\n";
}
when $b==0, it skips to the end of the loop.