I am trying to write a program that removes an entry from one of three lists. The program appears to work except the new files conf_list_* are empty except for the entries deleted. What am I missing?

#!/usr/bin/perl use strict; use warnings; use File::Copy ("cp"); my $announce_off = "master_conf_list_announce_off"; my $announce_on = "master_conf_list_announce_on"; my $beep_on = "master_conf_list_beep_on"; my $date = &getDate; my (%announce_off, %announce_on, %beep_on); print "$date\n"; #create Backup files in the backup folder. just incase anything goes +wrong. cp ("./master_list/$announce_off", "./master_list/backup/$announce_off +" . $date); cp ("./master_list/$announce_on", "./master_list/backup/$announce_on" +. $date); cp ("./master_list/$beep_on", "./master_list/backup/$beep_on" . $date) +; #create a scratch pad cp ("./master_list/$announce_off", "./master_list/$announce_off\.bak") +; cp ("./master_list/$announce_on", "./master_list/$announce_on\.bak"); cp ("./master_list/$beep_on", "./master_list/$beep_on\.bak"); #delete original files unlink ("./master_list/$announce_off"); unlink ("./master_list/$announce_on"); unlink ("./master_list/$beep_on"); #open files for reading open my $ANNOUNCE_OFFFH, '<', "./master_list/$announce_off\.bak"; open my $ANNOUNCE_ONFH, '<', "./master_list/$announce_on\.bak"; open my $BEEP_ONFH, '<', "./master_list/$beep_on\.bak"; open my $DELETE_LISTFH, '<', "$ARGV[0]"; #open files for writing open my $ANNOUNCE_OFFNEW, '>>', "./master_list/$announce_off"; open my $ANNOUNCE_ONNEW, '>>', "./master_list/$announce_on"; open my $BEEP_ONNEW, '>>', "./master_list/$beep_on"; open my $DELETED_ITEMS, '>>', "./deleted_items.txt"; #slurp each file into hash foreach (<$ANNOUNCE_OFFFH>){ chomp($_); $announce_off{$_} = 1; } foreach(<$ANNOUNCE_ONFH>){ chomp($_); $announce_on{$_} =1; } foreach(<$BEEP_ONFH>){ chomp($_); $beep_on{$_} = 1; } #parse through the list to delete for items to delete #print in either the old location or a liste of deleted files foreach (<$DELETE_LISTFH>){ chomp($_); print { exists $announce_off{$_} ? $ANNOUNCE_OFFNEW : $DELETED_ITE +MS } $_ ."\n"; print { exists $announce_on{$_} ? $ANNOUNCE_ONNEW : $DELETED_ITEMS +} $_ ."\n"; print { exists $beep_on{$_} ? $BEEP_ONNEW : $DELETED_ITEMS } $_ . +"\n"; } close $ANNOUNCE_OFFNEW; close $ANNOUNCE_ONNEW; close $BEEP_ONNEW; close $DELETED_ITEMS; sub getDate(){ my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my(@weekDays) = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $day +OfWeek, $dayOfYear, $daylightSavings) = localtime(); my($year) = 1900 + $yearOffset; my($theTime) = "\_$dayOfMonth\_$months[$month]\_$hour$minute"; return $theTime; }

Thanks for any assistance in advance.

EDIT:

ok, so I know I have it backwards. When I parse through my files I don't actually DELETE the item, I just choose which file to print it to. Since I am just testing if a key exists, and if it does, I am printing it to a file. So the reason I come up with empty files is that I never print anything to my files...

rookie mistake

So this leads me to my next question, how do I remove said entries from the hash? I'll check Google. Does any one have any suggestions on a better way to do this? I'd like any comments/constructive criticisms.


In reply to Remove From List by PyrexKidd

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.