Ahh, that's a bit more complex than the usual learning Perl question, at the risk of undoing the learning value of the exercise try the following
Code:
#!/usr/bin/perl
use strict;
# In a production system these should be validated before progessing, but for now...
print "Page access: ";
chomp(my @pa=split(/,\s+/,<STDIN>)); # assumes separated by comma and spaces as in your example
print "Frames: ";
chomp(my $frames=<STDIN>);
my @frames; # set up an array to hold an array for each frame.
for (my$count=0;$count<$frames;$count++){ #Process the array of arrays (see perldoc perlref for details of using array references)
for (my $index=0;$index<@pa;$index++){ #Deep copying the elements of the Page access into each frame array
${$frames[$count]}[$index]=$pa[$index];
}
@{$frames[$count]}[0 .. ($count - 1)]=split('',"-"x$count) if $count; #Set the leading irrellevant values to '-'
for (my $index=$count;$index<@{$frames[$count]};$index+=$frames){ # go through the frame array by whatever frame size we set
${$frames[$count]}[$index +2 ] =${$frames[$count]}[$index+1]=$pa[$index];
}
#truncate the array at the size of @pa
@{$frames[$count]}=@{$frames[$count]}[0..(@pa - 1)];
}
#Print out your results
my $count=1;
print "PA:\t",join(' ', @pa),"\n";
for my $frame_array_ref (@frames){
print " F$count:\t",join(' ', @{$frame_array_ref}),"\n";
$count++;
}
# I have no idea what the PF line represents, sorry
This User Gave Thanks to Skrynesaver For This Post:
I wish to write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted order by the file name.
• By default, the program displays only file names.
• By default, the program lists the files in the current directory.
• The program must provide the... (2 Replies)
could i get any help with how to link this program together. i dont know what to put where the X's are
print `flush`;
thank(); #print thank header
use Getopt::Std; # use declaration with the options function
getopts("ld:") or usage() and exit; ... (3 Replies)
Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX
I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Hi
I am new to perl, i need to write a program to convert horizontal words to vertical
eg: cat, dog, cow,.....(text file)
this should be written as
1.cat
2.dog
like this. can u pls help me to work out.. (4 Replies)
I want to traverse a durectory for a particular file. Situataion is like this. Path is ABC/a/c/g. it has around 100 folders in it.
Search a directory which has word "*latest*" in its path.
and then from the latest go through z/x/c to file final.html.
In total, i want it to go through... (4 Replies)
can anyone help me out to write a code by connecting to the sql database and I need to print the list of tables present in the databse.
any ideas please. (1 Reply)
I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade.
I have:
if ( $response =~ m/^/ ) {
$user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
LEARN ABOUT MOJAVE
module::loaded
Module::Loaded(3pm) Perl Programmers Reference Guide Module::Loaded(3pm)NAME
Module::Loaded - mark modules as loaded or unloaded
SYNOPSIS
use Module::Loaded;
$bool = mark_as_loaded('Foo'); # Foo.pm is now marked as loaded
$loc = is_loaded('Foo'); # location of Foo.pm set to the
# loaders location
eval "require 'Foo'"; # is now a no-op
$bool = mark_as_unloaded('Foo'); # Foo.pm no longer marked as loaded
eval "require 'Foo'"; # Will try to find Foo.pm in @INC
DESCRIPTION
When testing applications, often you find yourself needing to provide functionality in your test environment that would usually be provided
by external modules. Rather than munging the %INC by hand to mark these external modules as loaded, so they are not attempted to be loaded
by perl, this module offers you a very simple way to mark modules as loaded and/or unloaded.
FUNCTIONS
$bool = mark_as_loaded( PACKAGE );
Marks the package as loaded to perl. "PACKAGE" can be a bareword or string.
If the module is already loaded, "mark_as_loaded" will carp about this and tell you from where the "PACKAGE" has been loaded already.
$bool = mark_as_unloaded( PACKAGE );
Marks the package as unloaded to perl, which is the exact opposite of "mark_as_loaded". "PACKAGE" can be a bareword or string.
If the module is already unloaded, "mark_as_unloaded" will carp about this and tell you the "PACKAGE" has been unloaded already.
$loc = is_loaded( PACKAGE );
"is_loaded" tells you if "PACKAGE" has been marked as loaded yet. "PACKAGE" can be a bareword or string.
It returns falls if "PACKAGE" has not been loaded yet and the location from where it is said to be loaded on success.
BUG REPORTS
Please report bugs or other issues to <bug-module-loaded@rt.cpan.org<gt>.
AUTHOR
This module by Jos Boumans <kane@cpan.org>.
COPYRIGHT
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
perl v5.18.2 2013-11-04 Module::Loaded(3pm)