Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

skipping lines

by wolverina (Beadle)
on Dec 27, 2003 at 08:20 UTC ( #317167=perlquestion: print w/replies, xml ) Need Help??

wolverina has asked for the wisdom of the Perl Monks concerning the following question:

I'm kind of new at pattern matching.. trying to skip lines in a file that start with #. Any Idea's? -Lisa

Replies are listed 'Best First'.
Re: skipping lines
by Anonymous Monk on Dec 27, 2003 at 08:30 UTC
Re: skipping lines
by davido (Cardinal) on Dec 27, 2003 at 16:28 UTC
    There's also the substr method.

    while ( <FILE> ) { next if substr( $_, 0, 1 ) eq '#'; }
    For simple matches anchored to a non-varying character position, substr may be a little quicker, but at the cost of being a little less Perlish. In the end, it probably doesn't matter which you use.


    Dave

Re: skipping lines
by Anonymous Monk on Dec 27, 2003 at 10:24 UTC
    Where is your effort in this? What have you tried already?

    Next time, please read through the documentation which is shipped with Perl or have a browse through that on this site, then, if you are stuck, post your question and show us what you have already tried - This is important in that not only does it show some effort on your part, but it allows those who post answers to your questions to better tailor the solution to your task.

      ...I'm in agreement with Paulster2 here. My initial reaction was that this response does contain accurate and sound advice. But the fact that it came from an AM, and the fact that it ultimately offered no direct practical positive suggestions really stepped out of the spirit of PM for me.

      I gave up on clpm a long time ago because all questions there were pretty much greeted with a cheerful RTFM, and I could get that by just hanging around with my geek friends. (Many of whom learned Perl from me.)

      Simply telling someone to read the documentation that came with the package isn't really practical as significant good advice. A pointer to the specific section, and perhaps a small example of the sort of thing that is involved in the problem would be best (IMHO).

      I do agree with the reaction that this question didn't reflect much prior effort on the part of the poster, nor did it show any evidence of experimental attempts to solve the problem. On the other hand, a reasonable response would be to offer a couple of experiments to try, and encourage the poster to return here with her results for further discussion.

      When we keep them in the game with us by encouraging them cheerfully, they learn and then return here to answer questions for others. The community can live on. And that's why we do this. It's why we sign our names to our work.

      ...All the world looks like -well- all the world, when your hammer is Perl. ---v

        My initial reaction was that this response does contain accurate and sound advice. But the fact that it came from an AM, and the fact that it ultimately offered no direct practical positive suggestions really stepped out of the spirit of PM for me.

        I must say, these statements have me boggled. You make three primary claims about the preceding post:

        1. it contains accurate and sound advice
        2. it was posted anonymously
        3. it offered no practical positive suggestions

        Not only do I find it difficult to reconcile points 1 and 3 --- accurate sound advice has always seemed of practical and positive value to me --- but that the anonymity of the post plays a decisive role in your finding it to be outside the spirit of PM is, in my mind, shamefully disappointing.

        Anonymous monks are welcome here.
        But the fact that it came from an AM, and the fact that it ultimately offered no direct practical positive suggestions really stepped out of the spirit of PM for me.
        I don't see the connection between the anonymity and your criticism (IMO, unfounded) of the content.

        Let me say it again: anonymous monks are welcome here.

        Indeed, the OPs question was immediately and succinctly answered by an AM.

        It's entirely possible that that same AM was troubled that the OP didn't provide enough info to allow a response to give meaningful tips on where in the documentation to look, what tutorials would be helpful, etc. and followed up later with the suggestion for how to post a question that would indicate enough to allow a responder to give meaningful advice for further learning.

        I would have a problem with AM's response if the actual question wasn't answered, but in this case, an answer was posted almost 2 hours before.

      Gee, maybe if you didn't log on as an AM it would show a little effort on YOUR part. I really hate when AM's only offer negative feedback.

      Paulster2

        Gee, maybe if you didn't log on as an AM it would show a little effort on YOUR part. I really hate when AM's only offer negative feedback.

        Yeah, that's only a few steps above someone making a negative appraisal of a post based on identity (or non-identity as it were).

Re: skipping lines
by Limbic~Region (Chancellor) on Dec 28, 2003 at 03:45 UTC
    Lisa,
    Depending on lots of factors, you may want to consider a regex solution that handles leading white spaces as well.
    next if /^\s*#/;
    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://317167]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-06-05 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (23 votes). Check out past polls.

    Notices?