Hello karthik92,

Welcome to the Monastery. Well it looks the fellow Monk 1nickt provided an answer to your question. Just to include a two more alternative solutions:

#!/usr/bin/perl use strict; use warnings; # use Benchmark qw(:all) ; # WindowsOS use Benchmark::Forking qw( timethese cmpthese ); # UnixOS my $str = " test of white space"; my $results = timethese(100000000, { 'regex' => sub { $str =~ /^\s/ }, 'substr' => sub { substr($str, 0, 1) eq ' ' }, 'ord' => sub { ord($str) == 32 }, }, 'none'); cmpthese( $results ); __END__ $ perl test.pl Rate regex substr ord regex 9225092/s -- -44% -87% substr 16556291/s 79% -- -77% ord 73529412/s 697% 344% --

I used Benchmark to compare the alternative solutions and the fastest and best option on this case seems to be ord.

Update: Sample of the proposed solution:

my @strs = ("1234 pass 25 30 1", " pass 25 30 2", "1965 pass 35 45 1", " pass 35 45 2"); foreach my $sample (@strs) { if (ord($sample) == 32) { say "Matched: " . $sample; } } __END__ $ perl test.pl Matched: pass 25 30 2 Matched: pass 35 45 2

Update2: In case you are wondering about ord it simply reads the first character and returns the numeric value. From the ASCII table 32 decimal is SPACE number 1 (character) would return 49.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Delete a line by thanos1983
in thread Delete a line by karthik92

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.