Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

The Monastery Gates

( [id://131]=superdoc: print w/replies, xml ) Need Help??

New here?I want to ask a question of the Perl Monks. Where do I start?

If you're new here, please read PerlMonks FAQ
and Create a new user!

Quests
poll ideas quest 2025
Starts at: Jan 01, 2025 at 00:00
Ends at: Dec 31, 2025 at 23:59
Current Status: Active
1 reply by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
Toronto Perl Mongers presented Randal Schwartz: Half My Life with Perl
on Dec 18, 2024 at 10:13
0 replies by talexb

    Olaf Alders arranged to have Randal Schwartz come speak at a meeting of the Toronto Perl Mongers recently, and the video has now been posted on the TPRF channel. I've heard some of this history before, but it was really interesting to hear it directly from Randal.

    Alex / talexb / Toronto

    For a long time, I had a link in my .sig going to Groklaw. I heard that as of December 2024, this link is dead. Still, thanks to PJ for all your work, we owe you so much. RIP Groklaw -- 2003 to 2013.

DuckDuckGo Donates $25,000 to The Perl and Raku Foundation
on Dec 03, 2024 at 11:24
1 reply by marto
Supplications
PDL slice 2D array
2 direct replies — Read more / Contribute
by paul92
on Jan 18, 2025 at 10:44

    I'm trying to get a slice of a 2D PDL array and am having problems finding good examples of this. What I am trying to do is take Tick data and create create a OHLCV array based on a summarization of x number seconds. Any help would be apreciated. My code is below

#!/usr/bin/env perl use strict; use warnings; use PDL; use PDL::NiceSlice; use Time::Local; # Sample tick data: array of arrays [timestamp, price, volume] # Example: ["2025-01-12 09:30:00", 100.5, 200] my $tick_data = [ ["2025-01-12 09:30:00", 100.5, 200], ["2025-01-12 09:30:15", 101.0, 150], ["2025-01-12 09:30:30", 100.8, 100], ["2025-01-12 09:30:45", 101.2, 300], ["2025-01-12 09:31:00", 101.0, 250], ]; # Group data into OHLCV intervals (e.g., 1 minute) my $interval_seconds = 20; # Set interval in seconds # Helper: Convert timestamp to epoch sub timestamp_to_epoch { my ($timestamp) = @_; my ($date, $time) = split(' ', $timestamp); my ($year, $month, $day) = split('-', $date); my ($hour, $min, $sec) = split(':', $time); return timelocal($sec, $min, $hour, $day, $month - 1, $year); } # Pre-process: Add epoch to data my $data = pdl([ map { my $epoch = timestamp_to_epoch($_->[0]); [$epoch, $_->[1], $_->[2]] } @$tick_data ]); for my $i (0..$data->dim(1)-1) { my $ts = $data->at(0,$i); my $p = $data->at(1,$i); my $v = $data->at(2,$i); } # Find unique interval buckets my $start_epoch = $data((0), 0); my $intervals = floor(($data(0, -1) - $start_epoch) / $interval_seco +nds); # Compute OHLCV my ($open, $high, $low, $close, $volume) = ([], [], [], [], []); for my $i (0 .. max($intervals)) { my $group = $data->where(floor(($data - $start_epoch) / $interval_ +seconds)== $i); next if $group->nelem == 0; # Skip empty groups # push @$open, $group(0, 1); # First price # push @$high, max($group(:, 1)); # push @$low, min($group(:, 1)); # push @$close, $group((($group->dim(0) - 1)), 1); # Last price # push @$volume, sum($group(:, 2)); } # Convert OHLCV to PDL for display #my $ohlcv = pdl($open, $high, $low, $close, $volume)->transpose; # Output results #print "OHLCV Format (Open, High, Low, Close, Volume):\n"; #print $ohlcv;
dereferencing question
4 direct replies — Read more / Contribute
by sectokia
on Jan 17, 2025 at 00:23

    Hi monks, Given anonymous structures like:

my $array = [qw(a b c)]; my $hash = { a => 1, b => 2, c => 3 };

Is there a technical reason so many people/books use:

print $array->[2]; print $hash->{a};

Instead of saving 1 character and using:

print @$array[2]; print %$hash{a};
Prima: How to get a "table" layout?
3 direct replies — Read more / Contribute
by haj
on Jan 16, 2025 at 18:26

    Hello monks,

    In a Prima application I would like to define a widget which allows to set a bunch of configuration variables. So I have several lines, each consisting of a Prima::Label describing the entry and a Prima::InputLine where users can enter their values.

    Is there a decent way to get the InputLine widgets aligned vertically, like in a HTML table?

    Counting pixels and specifing the size attribute for the widgets works, sort of, but might break if the text in the Label widgets isn't known in advance, for example when it is pulled from some I18N framework. I would also prefer not to count pixels for the line height, which might differ for different platforms (or fonts).

    Any idea or pointer to a code example is welcome!

Naming a module that extracts subsets of a Linux system
3 direct replies — Read more / Contribute
by NERDVANA
on Jan 15, 2025 at 01:08
    Once again, I have a difficult-to-name module.

    Given a fully installed Linux (or BSD?) file tree, this module lets you select the files, directories, symlinks, device nodes, etc which you want to become part of a reduced system image. The purpose is to generate Linux initrd, or docker images, or portable chroots, or embedded system images. The cool features are:

    • It inspects the 'ldd' output on ELF binaries to determine which libs need added
    • It preserves permissions and mtimes of files and the directories that contain them (unlike mkdir -p)
    • It can move executables to new locations (like moving them to /newprefix/bin/)
    • It can rewrite interpreter paths of scripts to match their new location
    • It can rewrite the lib paths of ELF files so that they can live alongside an incompatible libc ecosystem

    I'm actually not even sure it belongs on CPAN, because while I keep writing code like this, it's always fairly specialized and I have no idea if my hacks and special cases will be useful for a different environment.

    I'm leaning toward "Linux::SystemSlicer" (i.e. like a slice of an array) but other phrases that come to mind are "Filesystem Subset Extractor", "Root Image Collector", "Initrd Builder", or "System Minifier". I'm only planning to ever use it on Linux, but I think it could theoretically be applied to BSD? There are probably a huge number of additional special cases that would be needed for anything other than Linux.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2025-01-19 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (59 votes). Check out past polls.