Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Reading "slices" out of a file at known start markers

by Tanktalus (Canon)
on Oct 03, 2008 at 05:11 UTC ( #715134=note: print w/replies, xml ) Need Help??


in reply to Reading "slices" out of a file at known start markers

I'd likely try something entirely different:

#!/usr/bin/perl use strict; use warnings; my @file; while(<DATA>) { # if we end in a backslash, add the next line... # (more error checking probably is required if we're at eof, # but I'll leave that as an excersise for the reader ;-) while (s/\\\s*\Z//) { $_ .= <DATA> } push @file, $_; } print @file; __DATA__ YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS) LTYACCCOMPILE = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) + \ --mode=compile $(YACC) $(YFLAGS) $(AM_YFLAGS) YLWRAP = $(top_srcdir)/ylwrap SOURCES = $(libpiuserland_la_SOURCES) $(pilot_addresses_SOURCES) + \ $(pilot_clip_SOURCES) $(pilot_csd_SOURCES) + \ $(pilot_debugsh_SOURCES) $(pilot_dedupe_SOURCES) + \ $(pilot_dlpsh_SOURCES) $(pilot_file_SOURCES) + \ $(pilot_foto_SOURCES) $(pilot_foto_treo600_SOURCES) + \ $(pilot_foto_treo650_SOURCES) $(pilot_getram_SOURCES) + \ $(pilot_getrom_SOURCES) $(pilot_getromtoken_SOURCES) + \ $(pilot_hinotes_SOURCES) $(pilot_install_datebook_SOURCES) + \ $(pilot_install_expenses_SOURCES) + \ $(pilot_install_hinote_SOURCES) $(pilot_install_memo_SOURCES) + \ $(pilot_install_netsync_SOURCES) $(pilot_install_todo_SOURCES) + \ $(pilot_install_todos_SOURCES) $(pilot_install_user_SOURCES) + \ $(pilot_memos_SOURCES) $(pilot_nredir_SOURCES) + \ $(pilot_read_expenses_SOURCES) $(pilot_read_ical_SOURCES) + \ $(pilot_read_notepad_SOURCES) $(pilot_read_palmpix_SOURCES) + \ $(pilot_read_screenshot_SOURCES) $(pilot_read_todos_SOURCES) + \ $(pilot_read_veo_SOURCES) $(pilot_reminders_SOURCES) + \ $(pilot_schlep_SOURCES) $(pilot_wav_SOURCES) + \ $(pilot_xfer_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive + \ html-recursive info-recursive install-data-recursive + \ install-dvi-recursive install-exec-recursive + \ install-html-recursive install-info-recursive + \ install-pdf-recursive install-ps-recursive install-recursive + \ installcheck-recursive installdirs-recursive pdf-recursive + \ ps-recursive uninstall-recursive

Replies are listed 'Best First'.
Re^2: Reading "slices" out of a file at known start markers
by repellent (Priest) on Oct 03, 2008 at 08:47 UTC
    We can avoid pushing into an array @file if the goal is just to print it out:
    while(<DATA>) { chomp; # find out if there's a line continuation # and remove the trailing backslash my $cont = s/\\\s*$//; # print without newline, no matter what print; # decide whether to end print with newline print "\n" unless $cont; }

    Update: Actually, a simple substitution would suffice:
    while (<DATA>) { s/\\\s*\n//; print; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://715134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2021-02-27 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?