On Sunday 29 August 2010 14:15:52 Kaushal Shriyan wrote:
> Hi
> 
> Can someone please explain me with an example of the usage chomp ()
> builtin function in perl.

Yes, here you go. Let's suppose you want to write a small grep programs that 
only prints all lines ending with the character "\". You can write:

[code]
#!/usr/bin/perl

use strict;
use warnings;

while (my $line = <>)
{
        # Remove the optional trailing newline character.
        chomp($line);

        # If $line ends with a backslash - print it.
        if ($line =~ m{\\\z})
        {
                print "$line\n";
        }
}
[/code]

Hope it helps.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to